#7560 closed (fixed)
Delegate (most) type conversion to backends
Reported by: | Leo Soto M. | Owned by: | Malcolm Tredinnick |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Keywords: | jython db-be-api | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
As discussed on the Mailing list and on IRC, some backends would be greatly simplified if they stop receiving string values for non-basic types, such as dates and decimal.
This patch delegates most of the get_db_prep_*
logic of these fields to backend methods (named value_to_db_something
where something
is date, time, decimal, etc) It also implements get_db_prep_*
for basic field types to avoid leaking string values.
For Jython/zxJDBC compatibility purposes, an special check was made on Field.get_db_prep_lookup
and 'year'
lookup. I was not able to understand it, so I choose to introduce as few modifications as possible there. It could be a good idea to delegate that logic to the backend too, but I think a second opinion is needed.
Finally, PhoneNumberField
doesn't inherits from IntegerField
anymore. There was no point on such inheritance, as phones are mapped to varchar fields on every backend. Not to mention that every method declared by IntegerField
was overriden by PhoneNumberField
.
This was tested against mysql, postgresql, oracle and sqlite3, and didn't broke anything (that wasn't already broken on trunk, at least).
Attachments (8)
Change History (18)
by , 17 years ago
Attachment: | get_db_prep_refactor.patch added |
---|
by , 16 years ago
Attachment: | get_db_prep_refactor2.patch added |
---|
comment:1 by , 16 years ago
milestone: | → 1.0 beta |
---|
Setting 1.0beta milestone, as Jython (and others Python VM such as PyPy) compatibility is on the 1.0 maybe list.
follow-up: 3 comment:2 by , 16 years ago
This looks good at first glance. There's some commented-out code and # XXX
comments that need to be removed/resolved; I'll read the patch in more detail a bit later and leave more feedback then.
In the meantime, Leo: can you post a summary of this ticket and the change to django-dev and make sure nobody sees problems with the general approach? Now that you have a working patch a final discussion of weather we should be doing this needs to happen real quick.
comment:3 by , 16 years ago
Replying to jacob:
This looks good at first glance. There's some commented-out code and
# XXX
comments that need to be removed/resolved;
Oh. Well, the commented out code was accidental. But the #XXX
s where left on purpose, to make sure that the question doesn't remain unanswered when/if the commit occurs.
by , 16 years ago
Attachment: | get_db_prep_refactor-3.patch added |
---|
Updated to current trunk. Also refactors year lookup code.
comment:4 by , 16 years ago
Hmm. I discovered that this refactor breaks _get_next_or_previous_by_FIELD
on DateTime
and Time
fields. That's because Model._get_next_or_previous_by_FIELD
always coerces the "current" value as string, then datetimes (and times) are converted to a string with usecs that can't be parsed later by DateTimeField.to_python
.
So I'm going to improve the to_python
method on both DateTimeField and TimeField.
by , 16 years ago
Attachment: | get_db_prep_refactor-4.patch added |
---|
Also fixes to_python on Time and DateTime fields. Includes tests for this addition.
comment:5 by , 16 years ago
Keywords: | db-be-api added |
---|
by , 16 years ago
Attachment: | get_db_prep_refactor-5.patch added |
---|
Avoid failing test if the backend doesn't support usecs
by , 16 years ago
Attachment: | 7560_get_db_prep_refactor.diff added |
---|
comment:6 by , 16 years ago
Yet another patch update. This time, I've also removed some code duplication of almost all get_db_prep_save
/get_db_prep_lookup
methods, as discussed on http://groups.google.com/group/django-developers/browse_thread/thread/29f95436ed433d85.
comment:7 by , 16 years ago
BTW, after the get_db_prep_value
addition, I included changes to the documentation on the patch. I'm sure that it needs many changes as my English is not on par with the quality of Django docs.
by , 16 years ago
Attachment: | 7560_get_db_prep_refactor.3.diff added |
---|
Fixes for TimeField.to_python and extra tests
comment:8 by , 16 years ago
Owner: | changed from | to
---|
I started reviewing this last night. Will get it committed today or tomorrow.
comment:9 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Patch against revision 7818