Opened 17 years ago

Closed 16 years ago

#3689 closed (fixed)

__year search trouble on 1st of january

Reported by: Dirk Datzert <dummy@…> Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Keywords:
Cc: nesh@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

Hi,

I detected in a data_hierarchy filter a strange behavior of dates at 1.1. of a year. I have a field birthday defined as a models.DateField(...). I'm working with a sqlite3 database, python2.5 and django-trunk.

Selecting in the admin view the year say 1990 all dates above 1.1.1990 are selected but not the 1.1.1990 himself.
Maybe this was introduced by the [4505] patch!?

Regards,
Dirk

Attachments (4)

year-search.patch (663 bytes ) - added by Dirk Datzert <dummy@…> 17 years ago.
this would fix my problem
sqlite.diff (1.8 KB ) - added by Nebojsa Djordjevic <nesh@…> 17 years ago.
patch + tests
sqlite2.diff (2.1 KB ) - added by Nebojsa Djordjevic <nesh@…> 17 years ago.
whoops, old patch
sqlite3.diff (2.4 KB ) - added by Nebojsa Djordjevic <nesh@…> 17 years ago.
latest ;)

Download all attachments as: .zip

Change History (15)

by Dirk Datzert <dummy@…>, 17 years ago

Attachment: year-search.patch added

this would fix my problem

comment:1 by Dirk Datzert <dummy@…>, 17 years ago

Has patch: set
Needs tests: set

comment:2 by Malcolm Tredinnick, 17 years ago

Patch needs improvement: set
Triage Stage: UnreviewedAccepted

I'm pretty sure this is SQLite-specific and we've had similar bugs in the past. The problem is the SQLite does not treat "2007-01-01 00:00:00" the same as "2007-01-01" and we really need to be querying with the latter. Ticket #1460 shows the previous occurrence.

I think the change in this patch should not restrict the change just to the start date. That feels a bit asymmetrical. Shouldn't the final test also be "< (year+1)-01-01" ?

comment:3 by Nebojsa Djordjevic <nesh@…>, 17 years ago

Cc: nesh@… added

in reply to:  2 comment:4 by Nebojsa Djordjevic <nesh@…>, 17 years ago

Component: Admin interfaceDatabase wrapper

This is not just a admin problem any foo__year query is affected. I hit it today in my non-admin related code.

Replying to mtredinnick:

I think the change in this patch should not restrict the change just to the start date. That feels a bit asymmetrical. Shouldn't the final test also be "< (year+1)-01-01" ?

Here is my stab at this, patch now checks <(year+1)-01-01 and I added some tests also (in tests/regressiontests/datatypes/models.py hope that's OK)

Also, I found another place with 00:00:00 in _sqlite_date_trunc -- should we change this also?

(btw. should I change any of the triage fields after submitting patch?)

by Nebojsa Djordjevic <nesh@…>, 17 years ago

Attachment: sqlite.diff added

patch + tests

by Nebojsa Djordjevic <nesh@…>, 17 years ago

Attachment: sqlite2.diff added

whoops, old patch

comment:5 by Nebojsa Djordjevic <nesh@…>, 17 years ago

Strange, now I got:

File "/Users/nesh/Documents/workspace/django/tests/modeltests/basic/models.py", line ?, in modeltests.basic.models.__test__.API_TESTS
Failed example:
    Article.objects.filter(pub_date__year=2004)
Expected:
    []
Got:
    [<Article: Area woman programs in Python>]

Looking into it ...

comment:6 by Nebojsa Djordjevic <nesh@…>, 17 years ago

Strange, now is OK, maybe probem was with %s-1-1??

I added some future/past checks just to be sure.

by Nebojsa Djordjevic <nesh@…>, 17 years ago

Attachment: sqlite3.diff added

latest ;)

comment:7 by James Bennett, 17 years ago

Keywords: qs-rf added

#5365 was a duplicate.

comment:8 by James Bennett, 17 years ago

See also #5504 which is covering discussion of testing for these cases.

comment:9 by James Bennett, 16 years ago

#6141 was a duplicate and also had some patches.

comment:10 by Malcolm Tredinnick, 16 years ago

Keywords: qs-rf removed

comment:11 by Malcolm Tredinnick, 16 years ago

Resolution: fixed
Status: newclosed

(In [7150]) Fixed #3689, #5223 -- Fixed "1st of January" comparisons for SQLite without breaking the other backends.

Based on a patch from raminf and tests from Nebojsa Djordjevic.

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