-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Serialization/encoding data does not work with models #64
Comments
I am adding unittests for the TetraJSONEncoder/Decoders. @samwillis, you wrote Generally speaking, I tried to create a mermaid diagram - mainly to understand things better. graph TD;
subgraph python[Plain Python objects]
int
str
wrongModel[Model]
end
subgraph special[Special objects]
Model
datetime
end
JSONDecoder --> wrongModel
wrongModel --> TypeError
int --> JSONEncoder
str --> JSONEncoder
JSONEncoder --> JSON-object
Model --> TetraJSONEncoder
datetime --> TetraJSONEncoder
TetraJSONEncoder --> JSON-object
subgraph serialized[JSON object]
JSON-object
end
JSON-object --> JSONDecoder
JSON-object --> TetraJSONDecoder
JSONDecoder --> str
JSONDecoder --> int
TetraJSONDecoder --> Model
TetraJSONDecoder --> datetime
I already added model support to it: elif isinstance(obj, models.Model):
return {
"__type": f"model.{obj._meta.app_label}.{obj.__class__.__name__}",
"value": obj.pk,
} After a few tests, I would want to merge two others that seem to be added in the meantime to Django: elif isinstance(obj, datetime.timedelta):
return duration_iso_string(obj)
elif isinstance(obj, (decimal.Decimal, uuid.UUID, Promise)):
return str(obj) The tests that I created showed that when I encode and decode a simple model, it works flawlessly. But I have problems in a form that has a ForeignKey field despite the Js/Alpine data structure holding the correct index key of the model, it is not retrieved, and I can't see that the TetraJSONDecoder is ever called, when e.g. calling the "submit" method of the component. I'm stuck here. |
And on: {'key': None, 'account_type': 1, 'country': 'AT', 'federal_state': '1', 'title': None, 'company_name': None,
'health_service_type': 'doc', 'medical_speciality': 'gp', 'phone_number': None, 'comment': None,
'identity_proof': None, 'profession_proof': None, 'first_name': None, 'last_name': None, 'email': None,
'terms_conditions': True} this is a dict, and no special one with a Maybe then my way of encoding the data is completely wrong, see above in #64 (comment). Because the |
Maybe I am misunderstanding something. There are 2 classes in utils.py:
TetraJSONEncoder
andTetraJSONDecoder
. In theory, the purpose is clear, and I already extended both to handle models:But no matter how hard I debug tetra, I NEVER get the
TetraJSONEncoder.default()
method to get called. It is never, ever called.In
tetra/tetra/utils.py
Line 81 in 3864e45
.encode()
is called, and never.default()
.Is there anything I am missing?
@samwillis have you got a clue here? Maybe I did not fully understand the serialization workflow of Tetra.
The text was updated successfully, but these errors were encountered: