Oracle backend using bytes in isoformat
|Reported by:||fatal10110@…||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.6|
|Severity:||Normal||Keywords:||oracle isoformat dates|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
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 ?
Change History (6)
comment:1 follow-ups: ↓ 2 ↓ 3 Changed 10 months ago by manfre
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
comment:4 Changed 10 months ago by Claude Paroz <claude@…>
- Resolution set to fixed
- Status changed from new to closed