computed_field
Hi there, thanks for the great useful library.
A small issue I encounter when using computed fields is that they are evaluated for changes as well (when in effect they should not)?
Or am I missing something?
i.e.
@computed_field(return_type=dict)
def meta(self):
return dict(
detail_url=self.get_object_detail_path(id=self.get_detail_view_pk()),
)
on save i get a
(Pdb) self.model_has_changed
*** KeyError: 'meta'
at line changedetect.py:92-93
for field_name, model_field in self_compat.model_fields.items():
field_value = self.__dict__[field_name]
perhaps
field_value = self.__dict__.get(field_name, None)
There currently is no code to handle computed fields. I will look into this :)
I just created #34 to fix this issue. Sadly I cannot reproduce the issue, see https://github.com/team23/pydantic-changedetect/pull/34 for details. Can you point me into the right direction?
perhaps something to do with the type=dict?
my monkeypatch looks like
for field_name, model_field in self_compat.model_fields.items():
#
# NOTE! this here is the fix
# raised: https://github.com/team23/pydantic-changedetect/issues/33
#
field_value = self.__dict__.get(field_name, None)
@ddanier working with @rosscdh-tpg , I think we have a bug on our side not on your library. Doing last round of testing but if confirmed you can close #34 as no fix will be required. We will revert back to you shortly
Thanks for the update. I will close this issue then.
yep, we had a classmethod that was updating the definition of the class by mistake, this caused the computed field to be transformed in a Decorator on subsequent instantiated models. Sorry for the inconvenience