Code

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#8931 closed (invalid)

Queries on datetimefields return incorrect results in mysql

Reported by: ElliottM Owned by: nobody
Component: Database layer (models, ORM) Version: 1.0
Severity: Keywords: datetime mysql query
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

In my models, I have a Planet class. One of the fields in Planet is a datetime field called updated. I also have a class called Base that has an o2o to Planet. The Base class also has an FK called "owner"to the Player class.

When I want to find all the bases whose planets were updated in the last six weeks, I should be able to do the following:

six_weeks_ago=datetime.datetime.now()-datetime.timedelta(days=7*6)
bases=Base.objects.filter(planet__updated__gt=six_weeks_ago)

That query returns no results. However, if I further refine the query to get only the bases owned by a particular player, like follows:

player_bases=bases.filter(owner__id=22064)

That query returns 18 results, as expected. It think it's pretty obvious that narrowing down the search criteria should reduce the number of results, not increase them, and I know there are Bases that have been updated in the last 6 weeks.

Attachments (0)

Change History (2)

comment:1 follow-up: Changed 6 years ago by ElliottM

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

Turns out this was a problem with mysql and not with django.

comment:2 in reply to: ↑ 1 Changed 6 years ago by kmtracey

Replying to ElliottM:

Turns out this was a problem with mysql and not with django.

Some details of the mysql problem could be helpful for when the next person to hit this searches the tracker, finds this report, and re-opens this as a bug in Django. Is is a mysql bug logged in their bug system? A configuration problem?

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.