pretix icon indicating copy to clipboard operation
pretix copied to clipboard

Wrong type detection order

Open rapinf opened this issue 3 years ago • 2 comments

Hi,

By using pretix API, I get an exception when I use payment_term_last:

...
pretix_app |   File "/pretix/src/pretix/api/serializers/event.py", line 803, in validate
pretix_app |     validate_event_settings(self.event, settings_dict)
pretix_app |   File "/pretix/src/pretix/base/settings.py", line 3035, in validate_event_settings
pretix_app |     if payment_term_last.date(event) < event.presale_end.date():
pretix_app | TypeError: can't compare datetime.datetime to datetime.date

I Think you have a wrong order in type detection in https://github.com/pretix/pretix/blob/5d6302d5fd34d471d55681398653acd9f202ca36/src/pretix/base/reldate.py#L62

datetime is an instance of datetime.date. The test return a datetime instead of a date as expected

Frédéric

rapinf avatar Feb 28 '22 13:02 rapinf

I think the return values are correct, but the comparison should just be

        if payment_term_last.date(event) < event.presale_end:

raphaelm avatar Feb 28 '22 13:02 raphaelm

Yes, you can fix the issue in /pretix/src/pretix/base/settings.py But you have an issue in RelativeDateWrapper I think the method aims to return a date if data is an instance of datetime (L64 and L65), but this code is unreachable because datetime is a subclass of date.

rapinf avatar Feb 28 '22 14:02 rapinf