From 402e6d292fd8aa5dfd49166e80098122950053f7 Mon Sep 17 00:00:00 2001 From: Hasan Ramezani Date: Thu, 11 Jul 2019 21:13:36 +0200 Subject: Fixed #30602 -- Made Extract raise ValueError when using unsupported lookups for DurationField. --- django/db/models/functions/datetime.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'django/db/models') diff --git a/django/db/models/functions/datetime.py b/django/db/models/functions/datetime.py index 7a582aa404..665e0b931d 100644 --- a/django/db/models/functions/datetime.py +++ b/django/db/models/functions/datetime.py @@ -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 -- cgit v1.3