Skip to content
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

DictionaryField does not call the get_prep_value method of VirtualField before saving to DB #123

Open
ktosiek opened this issue Jun 17, 2015 · 8 comments

Comments

@ktosiek
Copy link

ktosiek commented Jun 17, 2015

I have a custom field that uses to_python/get_prep_value to (de)serialize a custom object.
Something like HandField from https://docs.djangoproject.com/en/1.8/howto/custom-model-fields/.

When I'm using that field in hstore.DictionaryField schema my object is cast to string which is not a sensible representation. I was expecting DictionaryField to clean values with get_prep_value before casting them to strings.

@nemesifier
Copy link
Member

This looks related to #114.

@nemesifier
Copy link
Member

Hi @ktosiek, what were you expecting exactly? Could you help me by giving me an example with:

  • model data
  • operation performed
  • expected behaviour
  • actual behaviour

I'm trying to replicate the behaviour you mentioned but I don't notice anything strange, so I need your help to replicate your use case.

@ktosiek
Copy link
Author

ktosiek commented Jun 28, 2015

I've made a repo with an example: https://github.com/ktosiek/django-hstore-issue-123-example.
HandField has dedicated code for serializing Hand to a string, but it looks like django-hstore uses str(value) as the serialization of Hand.

model data: https://github.com/ktosiek/django-hstore-issue-123-example/blob/master/example/example/models.py and https://github.com/ktosiek/django-hstore-issue-123-example/blob/master/example/example/fields.py
expected behaviour is those two tests passing: https://github.com/ktosiek/django-hstore-issue-123-example/blob/master/example/example/tests.py
actual behaviour: the test using my custom field without hstore passes, the other one fails (I think because Hand.__str__ is used for serialization instead of HandField.get_prep_value).

@nemesifier
Copy link
Member

hey @ktosiek, what about adapting a simplified version of those tests into django_hstore?

@ktosiek
Copy link
Author

ktosiek commented Jun 29, 2015

It would make more sense, yes :-)
I'll try to do it later today.

@nemesifier
Copy link
Member

thank you @ktosiek, whenever you have time, it will be easier to address it and solve it.

Do you think this is in anyway related to #114?

@nemesifier
Copy link
Member

PS: see also this section of the docs: http://djangonauts.github.io/django-hstore/#_developers_guide

@ktosiek
Copy link
Author

ktosiek commented Jun 30, 2015

I don't see any relation with #114.

ktosiek added a commit to ktosiek/django-hstore that referenced this issue Jun 30, 2015
ktosiek added a commit to ktosiek/django-hstore that referenced this issue Jun 30, 2015
@nemesifier nemesifier changed the title get_prep_value is not called on schema fields VirtualField does not call get_prep_value Jul 1, 2015
@nemesifier nemesifier changed the title VirtualField does not call get_prep_value DictionaryField does not call the get_prep_value method of VirtualField before saving to DB Jul 1, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants