#9522 closed (fixed)
Python serializer doesn't use base Serializer.get_string_value
Reported by: | Alexander Koshelev | Owned by: | Alexander Koshelev |
---|---|---|---|
Component: | Core (Serialization) | Version: | 1.0 |
Severity: | Keywords: | ||
Cc: | Axel Hecht, Christian Hammond | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Just now python serializer in handle_field
simple call getattr
to retrieve field value form the object:
smart_unicode(getattr(obj, field.name), strings_only=True)
And base Serializer has method get_string_value
that calls appropriate value_to_string
field method but derived serializers doesn't call it at all.
It causes problem than model has non-string field that cannot simply be converted to string.
Attachments (1)
Change History (16)
comment:1 by , 16 years ago
Needs tests: | set |
---|---|
Patch needs improvement: | set |
comment:2 by , 16 years ago
Yes, first attempt was not good. I've made some more changes and written the tests.
comment:3 by , 16 years ago
Needs tests: | unset |
---|---|
Patch needs improvement: | unset |
comment:4 by , 16 years ago
Cc: | added |
---|---|
Owner: | changed from | to
Status: | new → assigned |
I'm getting hit by this, too.
I found that the DeSerialization calls into to_python [1], so I wonder if the Serialization shouldn't just call into get_db_prep_save.
Or is it a safe assumption that feeding a string into to_python is always going to succeed?
[1] http://code.djangoproject.com/browser/django/trunk/django/core/serializers/python.py#L88
comment:5 by , 16 years ago
Owner: | changed from | to
---|---|
Status: | assigned → new |
comment:6 by , 16 years ago
Cc: | added |
---|
comment:8 by , 16 years ago
Are there any plans to get this in? It's proving to be a real problem for me. After some Googling, it seems several people are patching their Django sources to work around this.
comment:9 by , 16 years ago
milestone: | → 1.1 |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:10 by , 16 years ago
Patch needs improvement: | set |
---|
This patch is adding a value to every model in Django. I don't think this is the correct implementation. Models know nothing about serialization, and if we're going to start adding serialization information to them, we're going to need to have a much bigger discussion about it.
This change should be contained to the serializers, perhaps with a third party serializer that provides the functionality. Something along the lines of ./manage.py dumpdata --full-serialize=ModelName perhaps.
comment:11 by , 16 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:12 by , 16 years ago
Owner: | changed from | to
---|---|
Patch needs improvement: | unset |
Status: | assigned → new |
Oh, where do you find "adding value to every model"? Patch doesn't do it at all. It only adds flag attribute to model *field* and field already knows how to convert it to string. And this knowledge is used in serializers just now.
comment:13 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Quick and dirty is fine, but you're not going to convince me to apply the patch without a test case - ideally, something integrated into the Django test suite, but at the very least, a model definition and python session that demonstrates the problem.