#28827: query with ExtractHour and calculation like
"values(minutes=(ExtractHour('dt_start') * 60))" gives an pytz error:
AttributeError: 'int' object has no attribute 'tzinfo'
-------------------------------------+-------------------------------------
Reporter: Martijnth | Owner: nobody
Type: Bug | Status: new
Component: Database | Version: 1.11
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
The generated query works fine in MySQL, guess Django still thinks the
result is a datetime/timezone object
but it has become an integer because of the calculation.
---------------------------------------------------------------------------
AttributeError Traceback (most recent call
last)
<ipython-input-1-b1fc61315659> in <module>()
---> 47 print(a)
/Users/martijntenhoor/projects/bluebi/rms-drf-api/virtual/lib/python3.5
/site-packages/django/db/models/query.py in __repr__(self)
224
225 def __repr__(self):
--> 226 data = list(self[:REPR_OUTPUT_SIZE + 1])
227 if len(data) > REPR_OUTPUT_SIZE:
228 data[-1] = "...(remaining elements truncated)..."
/Users/martijntenhoor/projects/bluebi/rms-drf-api/virtual/lib/python3.5
/site-packages/django/db/models/query.py in __iter__(self)
248 - Responsible for turning the rows into model
objects.
249 """
--> 250 self._fetch_all()
251 return iter(self._result_cache)
252
/Users/martijntenhoor/projects/bluebi/rms-drf-api/virtual/lib/python3.5
/site-packages/django/db/models/query.py in _fetch_all(self)
1116 def _fetch_all(self):
1117 if self._result_cache is None:
-> 1118 self._result_cache = list(self._iterable_class(self))
1119 if self._prefetch_related_lookups and not
self._prefetch_done:
1120 self._prefetch_related_objects()
/Users/martijntenhoor/projects/bluebi/rms-drf-api/virtual/lib/python3.5
/site-packages/django/db/models/query.py in __iter__(self)
104 names = extra_names + field_names + annotation_names
105
--> 106 for row in compiler.results_iter():
107 yield dict(zip(names, row))
108
/Users/martijntenhoor/projects/bluebi/rms-drf-api/virtual/lib/python3.5
/site-packages/django/db/models/sql/compiler.py in results_iter(self,
results)
840 for row in rows:
841 if converters:
--> 842 row = self.apply_converters(row, converters)
843 yield row
844
/Users/martijntenhoor/projects/bluebi/rms-drf-api/virtual/lib/python3.5
/site-packages/django/db/models/sql/compiler.py in apply_converters(self,
row, converters)
825 value = row[pos]
826 for converter in convs:
--> 827 value = converter(value, expression,
self.connection, self.query.context)
828 row[pos] = value
829 return tuple(row)
/Users/martijntenhoor/projects/bluebi/rms-drf-api/virtual/lib/python3.5
/site-packages/django/db/backends/mysql/operations.py in
convert_datetimefield_value(self, value, expression, connection, context)
237 if value is not None:
238 if settings.USE_TZ:
--> 239 value = timezone.make_aware(value,
self.connection.timezone)
240 return value
241
/Users/martijntenhoor/projects/bluebi/rms-drf-api/virtual/lib/python3.5
/site-packages/django/utils/timezone.py in make_aware(value, timezone,
is_dst)
283 if hasattr(timezone, 'localize'):
284 # This method is available for pytz time zones.
--> 285 return timezone.localize(value, is_dst=is_dst)
286 else:
287 # Check that we won't overwrite the timezone of an aware
datetime.
/Users/martijntenhoor/projects/bluebi/rms-drf-api/virtual/lib/python3.5
/site-packages/pytz/__init__.py in localize(self, dt, is_dst)
225 '''Convert naive time to local time'''
226 print(dt)
--> 227 if dt.tzinfo is not None:
228 raise ValueError('Not naive datetime (tzinfo is
already set)')
229 return dt.replace(tzinfo=self)
AttributeError: 'int' object has no attribute 'tzinfo'
--
Ticket URL: <https://code.djangoproject.com/ticket/28827>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/052.db1a77c2d91e468c4d9e1a0bbf49dd22%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.