Open Jaymon opened 8 months ago
This was a comment in a models file I've been working on:
# TODO @address_hash.setter("address") meaning that it will call
# address_hash.fset(orm, "<VALUE RETURNED FROM ADDRESS FSET>"), it's
# basically a way to say address_hash depends on the value of address. Or we
# could have a .dset method that stands for "depends fset"
Ok, the idea would be you could do something like this:
That will cause
Schema.fields
to order the fields sothree
comes afterone
andtwo
. Likewise,Field.default
andField.fset
would be changed to check depends and call a newField.dget(orm, default_value)
method to get the value.This isn't perfect and I think there might some code paths I'm missing.
What prompted this was email addresses, I wanted to set a hash value when the email address was set, so I modified the address's
fset
method to set the hash value. The problem was when creating a newOrm
instance,Orm.__init__
callsField.fdefault
which would set the fields passed into__init__
tofields["hash"] = None
and then it would get passed toOrm.modify
which called address'sfset
method before seeing thefields["hash"]
value, which correctly set the value in hash, but then asOrm.modify
continued to iterate through fields it eventually got to thehash
key and value and then hash got set toNone
, wiping out the value the address field had previously set hash to.