1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #30602 -- Made Extract raise ValueError when using unsupported lookups for DurationField.

This commit is contained in:
Hasan Ramezani
2019-07-11 21:13:36 +02:00
committed by Mariusz Felisiak
parent 7a42cfcfdc
commit 402e6d292f
2 changed files with 15 additions and 0 deletions

View File

@@ -73,6 +73,14 @@ class Extract(TimezoneMixin, Transform):
raise ValueError(
"Cannot extract time component '%s' from DateField '%s'. " % (copy.lookup_name, field.name)
)
if (
isinstance(field, DurationField) and
copy.lookup_name in ('year', 'iso_year', 'month', 'week', 'week_day', 'quarter')
):
raise ValueError(
"Cannot extract component '%s' from DurationField '%s'."
% (copy.lookup_name, field.name)
)
return copy