AturSams
AturSams

Reputation: 7952

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.

Upvotes: 3

Views: 136

Answers (2)

GalDude33
GalDude33

Reputation: 7130

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!

Upvotes: 2

iniju
iniju

Reputation: 1094

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

I think GAE stores strings as unicodes.

Upvotes: 1

Related Questions