python - Why is the same object throwing a "NoneType" object Attribute error in one instance and not others? -


i using django set cart functionality on ecommerce site. items entered cart_items in mysql table.

before question, relevant code:

charm = false if postdata.get('charm_sku'):     charm_sku = postdata.get('charm_sku','')     ch = get_object_or_404(charm, sku=charm_sku)   #get products in cart cart_products = get_cart_items(request) product_in_cart = false # check see if item in cart cart_item in cart_products:     if cart_item.product.id == p.id:          if charm == true:               if cart_item.charm.id == ch.id:                  # update quantity if found                  cart_item.augment_quantity(quantity)                  product_in_cart = true          else:              if cart_item.charm.id == "":                 # update quantity if found                 cart_item.augment_quantity(quantity)                 product_in_cart = true 

edit: reworked code shown above, causing both if cart_item.charm.id's throw attirbuteerror: 'nonetype' object has no attribute 'id'. in way, think has improved situation, since suspect first 1 seeming "succeed" in fact first if charm == true failing, never testing first if cart_item.charm.id == ch.id. question remains: why trowing attributeerror, when loop declaring cart_item, , cart_items have both charm column , id's assigned said columns?

edit 2: can not reference cart_item nested if's? thing can think, @ same time feel should able to, maybe wrong?

nonetype means instead of instance of class, you've got none. means assignment failed or or function call returned unexpected result. assignment cart_item failing in case charm == false. check whatever code (assignment or function call) that's setting 2 variables.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -