Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GAE python string equality - strange behvaior with unicode

We are trying to compare strings, one is loaded from the datastore and the other is acquired from a HTML form using

modelID = self.request.get('fieldName')

Then we compare the two:

result = db.Query(modelName).filter('model_id =', modelID).fetch(limit=1)

But althout I checked the datastore viewer and clearly see that an entity exists with model_id = modelID, python insists they are not equal trampling my attempt to make my app work.

like image 622
AturSams Avatar asked Jun 30 '26 22:06

AturSams


2 Answers

Search for spaces in the string

you can use the string.strip() function to get rid of them! spaces are evil and will prevent equality...

take care man!

like image 194
GalDude33 Avatar answered Jul 03 '26 11:07

GalDude33


Try unicode(modelID) in the filter instead of modelID.

I think GAE stores strings as unicodes.

like image 21
iniju Avatar answered Jul 03 '26 12:07

iniju



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!