#15304: `Model.objects.create()` returns `long` instead of `int`.
-------------------------------------+-------------------------------------
Reporter: mrmachine | Owner: nobody
Type: Bug | Status: closed
Milestone: | Component: Database layer
Version: SVN | (models, ORM)
Resolution: wontfix | Severity: Normal
Triage Stage: Design | Keywords: int long primary
decision needed | key create get
Needs documentation: 0 | Has patch: 1
Patch needs improvement: 0 | Needs tests: 0
UI/UX: 0 | Easy pickings: 1
-------------------------------------+-------------------------------------
Changes (by mrmachine):
* easy: 0 => 1
Comment:
This ticket was accepted by a core dev. Work was done on a patch based on
feedback received. Why is it now marked wontfix? The ticket description
might be lacking a code example, and this might be an edge case, but this
is a real world problem in a real project that had us stumped for a few
hours.
"we use a pickle field to store various types of data -- PKs, dates and
times, booleans, dicts, etc. -- and when passing in the value of a newly
created PK to the pickle field we were then unable to filter on it unless
we explicitly searched for long values."
Our `PickleField.get_prep_value()` method converts a python value passed
to `QuerySet.filter()` (or `.get()`, etc.) into a pickle string so that we
can filter on pickle fields. The pickle string for 1 is not the same as
1L, so our filter doesn't return the data we expect. To work-around this
problem, we need to determine the type for primary key fields and coerce
the value on newly created model objects explicitly in our code before
pickling.
The primary key value returned by `Model.objects.create()` and
`Model.objects.get()` should be the same. It seems to be a clear bug that
the primary key value could be different types (and not the type specified
in your model class), and I don't see any downside in making it so. How is
it "not worth it" to fix? Do I need to include my implementation of
`PickleField` in the tests?
--
Ticket URL: <https://code.djangoproject.com/ticket/15304#comment:10>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.