tortoise / tortoise/tortoise-orm

The process of datetime and MySQL interaction is described implicitly

Open
#1,182 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
5.6k
Forks
516
Avg merge
2d 21h
Merged PRs (30d)
9

Description

Describe the bug
The process of datetime and MySQL interaction is described implicitly

To Reproduce

current_time = datetime.utcnow()
day_begin = datetime(current_time.year, current_time.month, current_time.day, 0, 0, 0)

where = Q(
  Q(put_time__gte=day_begin),
  Q(put_time__lt=current_time),
  join_type="AND"
)
 
await MyModel.filter(where).sql()
SELECT `name`,`put_time` 
FROM `table` 
WHERE `put_time`>='2022-07-14T00:00:00' 
AND `put_time`<'2022-07-14T11:34:32.436741'

Expected behavior
I am expected to receive all records that were created from 00:00 hours inclusive of the current day to the end time NOT included. In fact, we get records up to and including the end time because we are dealing with milliseconds because of datetime specifics.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the Python datetime and MySQL query shown in the report, then inspect the generated SQL and the database's datetime precision at the boundary. Confirm whether records exactly at the end time are included despite the less-than condition; done means the reported inclusive/exclusive behavior is explained and corrected or clearly documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
mysql, python
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.