The first positional argument to an IntegerProperty (which you're using for 'rank') is taken to be its datastore-name, which has to be a string. Did you mean this to be another ComputedProperty?
Function: Lambda is not a string — what does this mean?
-
09-07-2023 - |
Question
I'm relatively new to this, but I'm trying to create a computedproperty for my NDB entity in Google App Engine. Right now I have:
class Player(ndb.Model):
name = ndb.StringProperty(required=True)
wins = ndb.IntegerProperty(required=True)
losses = ndb.IntegerProperty(required=True)
record = ndb.ComputedProperty(lambda self: 1. * self.wins / (self.wins + self.losses))
rank = ndb.IntegerProperty(lambda self: self.record * 1000 if self.wins + self.losses >= 10 else 500 + 1000 * (self.record-0.5) * (self.wins+self.losses) * (self.wins+self.losses) / 100)
And one of these two lambda properties (I'm not sure which, since neither is line 850) is causing an error when I try to create a Player object. I get the message (on the console):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/ndb/model.py", line 850, in __init__
raise TypeError('Name %r is not a string' % (name,))
TypeError: Name <function <lambda> at 0x10c531a28> is not a string
What am I doing wrong? Why does the lambda function need to be a string? And, how can I make it into a string that does what I want it to do? I've tried a simpler version too, without the if/else statement, and I get the same error.
Let me know what else you need to know and I will be happy to oblige.
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow