I'm trying to make sure a score field I set for articles on my site in
unique, however, I'm running into an issue where my method is
appearing to corrupt my datastore. After I input stories, I can't view
pages, getting a return size too large error, and when I stop and
start the SDK, it won't restart.
Here's what I'm doing.
I set up a new Score Property.
------------------------------------------------------------------------------------
class ScoreProperty(db.FloatProperty):
def checkScoreValue(self, value):
query = db.GqlQuery('SELECT * FROM Story WHERE score = :1', value)
results = query.fetch(1)
if len(results) > 0:
raise db.BadValueError(
'Property %s must be unique' %
self.name)
return value
def __init__(self, verbose_name=None, name=None):
super(ScoreProperty, self).__init__(
verbose_name, name, required=False,
validator=self.checkScoreValue)
------------------------------------------------------------------------------------
Then when I go to add a story, I use this try statement
------------------------------------------------------------------------------------
story_added = False
while story_added == False:
try:
story.put()
story_added = True
except db.BadValueError:
story.score = story.score + 0.001
------------------------------------------------------------------------------------
What should happen is that when a put is attempted, a check is done to
see if a story with that score exists. If it does exist, add 0.001 and
try to put again. After adding several stories in batch mode, I can
using the data view that appears to be working, but strangely. I'll
see a score of ###.0 and then the next would be something like ###.
043, so I'm not sure what happened to .001-.0042. Also, after running
the process the datastore appears to be corrupted as well.
I'm considering swapping to using a DateTimeProperty and keying off of
the miliseconds to see if that is handled better, but I'm confused as
to why this current method is creating problems.
One thing that might be an issue is the development is happening on an
eeepc, which is a single core processor and it's SSD isn't the fast
read/write storage device.