Opened 17 months ago

Closed 17 months ago

Last modified 17 months ago

#21256 closed Bug (fixed)

Error in django.utils.datetime_safe.datetime.combine method

Reported by: Łukasz Owned by: nobody
Component: Utilities Version: 1.5
Severity: Release blocker Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

There seems to be an error in the combine() method of the django.utils.datetime_safe.datetime class. Current definition:

    def combine(self, date, time):
        return datetime(date.year, date.month, date.day, time.hour, time.minute, time.microsecond, time.tzinfo)

The time.second value is not passed to the datetime constructor. Moreover, this method should be a classmethod, like so:

    @classmethod
    def combine(cls, date, time):
        return cls(date.year, date.month, date.day, time.hour, time.minute, time.second, time.microsecond, time.tzinfo)

Change History (5)

comment:1 Changed 17 months ago by aaugustin

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Severity changed from Normal to Release blocker
  • Triage Stage changed from Unreviewed to Accepted

This bug has been corrupting data since #1443 was fixed, more than five years ago. It's interesting that it wasn't detected earlier.

(FWIW I don't really like datetime_safe.)

Since the fix is really trivial and it's a data corruption bug, I'm going to backport the fix back to 1.4.

comment:2 Changed 17 months ago by Aymeric Augustin <aymeric.augustin@…>

  • Resolution set to fixed
  • Status changed from new to closed

In d9b6fb8f61e5029ce5d45d8fcb75694cee046b8f:

Fixed #21256 -- Error in datetime_safe.datetime.combine.

comment:3 Changed 17 months ago by Aymeric Augustin <aymeric.augustin@…>

In ef9133768c2aed52646ad0b6274edf836aa672b2:

[1.5.x] Fixed #21256 -- Error in datetime_safe.datetime.combine.

Backport of d9b6fb8 from master

comment:4 Changed 17 months ago by Aymeric Augustin <aymeric.augustin@…>

In ea04c81d372aaa1b1aebdacefc46735ef9559fb6:

[1.4.x] Fixed #21256 -- Error in datetime_safe.datetime.combine.

Backport of d9b6fb8 from master

comment:5 Changed 17 months ago by Aymeric Augustin <aymeric.augustin@…>

In 5591fe6829c458346982e39e777f1fdca69e9792:

[1.6.x] Fixed #21256 -- Error in datetime_safe.datetime.combine.

Backport of d9b6fb8 from master

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