diff options
| author | Hasan Ramezani <hasan.r67@gmail.com> | 2019-07-11 21:13:36 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-07-12 08:08:35 +0200 |
| commit | 402e6d292fd8aa5dfd49166e80098122950053f7 (patch) | |
| tree | 6de4e2ba2470bde994f9d025d0d9ed2190cfbb9b /django/db/models/functions | |
| parent | 7a42cfcfdc94c1e7cd653f3140b9eb30492bae4f (diff) | |
Fixed #30602 -- Made Extract raise ValueError when using unsupported lookups for DurationField.
Diffstat (limited to 'django/db/models/functions')
| -rw-r--r-- | django/db/models/functions/datetime.py | 8 |
1 files changed, 8 insertions, 0 deletions
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 |
