#22551 closed Bug (fixed)
Oracle backend using bytes in isoformat
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.6 |
Severity: | Normal | Keywords: | oracle isoformat dates |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
Hi , seems like we have some micro bug here, using oracle + django-celery :
File "-/site-packages/django/db/backends/oracle/base.py", line 449, in year_lookup_bounds_for_datetime_field return [b.isoformat(b' ') for b in bounds] File "-/site-packages/django/db/backends/oracle/base.py", line 449, in <listcomp> return [b.isoformat(b' ') for b in bounds] TypeError: isoformat() argument 1 must be a unicode character, not bytes
The reason of the excetion is "date_hierarchy" in admin part of django-celery
date_hierarchy = 'tstamp'
But it should work , beacause in models all is fine
tstamp = models.DateTimeField(_('event received at'), db_index=True)
From django documentation: " Set date_hierarchy to the name of a DateField or DateTimeField in your model, and the change list page will include a date-based drilldown navigation by that field."
The code in oracle/base.py
def year_lookup_bounds_for_datetime_field(self, value): # The default implementation uses datetime objects for the bounds. # This must be overridden here, to use a formatted date (string) as # 'second' instead -- cx_Oracle chops the fraction-of-second part # off of datetime objects, leaving almost an entire second out of # the year under the default implementation. bounds = super(DatabaseOperations, self).year_lookup_bounds_for_datetime_field(value) if settings.USE_TZ: bounds = [b.astimezone(timezone.utc).replace(tzinfo=None) for b in bounds] return [b.isoformat(b' ') for b in bounds]
Example from python documentantion of how to use the isoformat() method:
datetime(2002, 12, 25, tzinfo=TZ()).isoformat(' ')
They are not using b to convert the seperator to bytes..
Should I remove the b or it's important ?
Thanks.
Change History (6)
follow-ups: 2 3 comment:1 by , 11 years ago
comment:2 by , 11 years ago
Replying to manfre:
For Python 2.7, without the b:
TypeError: isoformat() argument 1 must be char, not unicode
Python 2.7 + ?
We are running django on Python 3...
comment:3 by , 11 years ago
Replying to manfre:
For Python 2.7, without the b:
TypeError: isoformat() argument 1 must be char, not unicode
oops, I did not read well your comment
I'm using Python 3 and its ok without the b ...
But if you will check the python documentation you will see that no matter wich version of python, they are using it without the b
comment:4 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
For Python 2.7, without the b: