Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#22551 closed Bug (fixed)

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
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)

comment:1 by Michael Manfre, 11 years ago

For Python 2.7, without the b:

TypeError: isoformat() argument 1 must be char, not unicode

in reply to:  1 comment:2 by fatal10110@…, 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...

in reply to:  1 comment:3 by fatal10110@…, 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 Claude Paroz <claude@…>, 11 years ago

Resolution: fixed
Status: newclosed

In 120a981207aacb7453c0e064ec5b3d011ec68345:

[1.6.x] Fixed #22551 -- Made oracle backend method Python 3 compatible

Thanks fatal10110 at gmail.com for the report. The fix is 1.6-only
because that code has been refactored in 1.7 (6983201cfb).

comment:5 by Claude Paroz <claude@…>, 11 years ago

In d5a9d74eec66ce7e21eae2d9a5065fdd637333c5:

[1.7.x] Fixed #22551 -- Made oracle backend method Python 3 compatible

Thanks fatal10110 at gmail.com for the report. The fix is 1.6-only
because that code has been refactored in 1.7 (6983201cfb).
'Docs-only' forward port of 120a98120 from 1.6.x.

comment:6 by Claude Paroz <claude@…>, 11 years ago

In 2ce51967638ac9f01c1c25bb33d51115ce99e0df:

Fixed #22551 -- Made oracle backend method Python 3 compatible

Thanks fatal10110 at gmail.com for the report. The fix is 1.6-only
because that code has been refactored in 1.7 (6983201cfb).
'Docs-only' forward port of 120a98120 from 1.6.x.

Note: See TracTickets for help on using tickets.
Back to Top