Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#24189 closed Bug (invalid)

Filtering by month or day doesn't work with MySQL

Reported by: Unai Zalakain Owned by: nobody
Component: Database layer (models, ORM) Version: 1.7
Severity: Normal Keywords: datetime, timezone, date, month, day
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

While filtering by year works, filtering by month or by date doesn't:

    In [1]: from planner.tasks.models import KeyDate
     
    In [2]: KeyDate.objects.all()
    Out[2]: [<KeyDate: Revision>, <KeyDate: Production>]
     
    In [3]: KeyDate.objects.all()[0].date
    Out[3]: datetime.datetime(2015, 1, 20, 14, 1, 20, tzinfo=<UTC>)
     
    In [4]: KeyDate.objects.filter(date__year=2015)
    Out[4]: [<KeyDate: Revision>, <KeyDate: Production>]
     
    In [5]: KeyDate.objects.filter(date__month=1)
    Out[5]: []

If I switch to SQLite everything works as expected.

Change History (3)

comment:1 by Unai Zalakain, 10 years ago

Resolution: invalid
Status: newclosed

After injecting timezone definitions it didn't work neither... until I restarted the MySQL server.

comment:2 by Aymeric Augustin, 10 years ago

MySQL thinks it's a good idea to return invalid results silently when something goes wrong. I'm sorry to hear that you have to use it.

in reply to:  2 comment:3 by Unai Zalakain, 10 years ago

Replying to aaugustin:

MySQL thinks it's a good idea to return invalid results silently when something goes wrong. I'm sorry to hear that you have to use it.

I'm sorry too, believe me, it's the first time I had to use MySQL and, compared to using PostgreSQL it's not a pleasant experience ... I hope we will eventually change to PostgreSQL...

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