Suppose I have an entity in my datastore that I know it can have a unique key_name deriving from a combination of it’s properties:
Example:
class Render(db.Model):
#Math props
x_size = db.IntegerProperty()
y_size = db.IntegerProperty()
center_axis_x = db.FloatProperty()
center_axis_y = db.FloatProperty()
center_axis_z = db.FloatProperty()
iterations = db.IntegerProperty()
I am sure that there can be no other entity with the exact same properties so in order to create the unique key I user so far:
render_key=hashlib.md5(str(properties.x_size) +
str(properties.y_size) +
str(properties.iterations) +
str(properties.center_axis_x) +
str(properties.center_axis_y) +
str(properties.center_axis_z)
).hexdigest()
The hexdigest let’s me make the key url-safe and user friendly but I believe it might need discussion as well.
So to the question. In the above scenario or an altered version of that, are there any other better ways to achieve the same result? It doesn’t need to be backward compatible. So even if the final key differs from the one generated by my method it’s not a problem.
Thanks
Overall your plan is good, except that md5 doesn’t guarantee that you won’t have collisions (although it’s very unlikely). You can make collisions even more unlikely by using SHA-256 instead, or just don’t hash it and you’re good to go.
Depends on whether you’re ok with living with the very rare case that a collision does occur and you overwrite the wrong entity.