You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ok, the idea would be you could do something like this:
one = Field(str)
two = Field(str)
three = Field(str, depends=["one", "two"])
That will cause Schema.fields to order the fields so three comes after one and two. Likewise, Field.default and Field.fset would be changed to check depends and call a new Field.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 new Orm instance, Orm.__init__ calls Field.fdefault which would set the fields passed into __init__ to fields["hash"] = None and then it would get passed to Orm.modify which called address's fset method before seeing the fields["hash"] value, which correctly set the value in hash, but then as Orm.modify continued to iterate through fields it eventually got to the hash key and value and then hash got set to None, wiping out the value the address field had previously set hash to.
The text was updated successfully, but these errors were encountered:
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.The text was updated successfully, but these errors were encountered: