You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
I have a project that is a table created by django with a time field called models.DateTimeField that records the time in the database as follows: 2022-07-29 11:00:24.794
I created a new fastapi project, using tortoise-orm to connect to Oracle database
There are two problems:
When I define the time field in the model, if I define the field like this:
EDIT_DATE = fields.DatetimeField(description=' Modify date ')
The following error is reported:
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 693, in lifespan
async with self.lifespan_context(app) as maybe_state:
File "/usr/lib64/python3.11/contextlib.py", line 210, in aenter
return await anext(self.gen)
^^^^^^^^^^^^^^^^^^^^^
File "/home/whatsup_alarm/core/event.py", line 29, in lifespan
await get_whatsup_servers_information()
File "/home/whatsup_alarm/core/event.py", line 41, in get_whatsup_servers_information
objs = await NetDeviceSysMonitor.filter(**filter_par)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/tortoise/queryset.py", line 1151, in _execute
instance_list = await self._db.executor_class(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/tortoise/backends/base/executor.py", line 139, in execute_select
instance: "Model" = self.model._init_from_db(**dict(row_items[:current_idx]))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/tortoise/models.py", line 754, in _init_from_db
setattr(self, model_field, field.to_python_value(kwargs[key]))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/tortoise/fields/data.py", line 354, in to_python_value
value = parse_datetime(value)
^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/iso8601/iso8601.py", line 124, in parse_date
raise ParseError(e)
iso8601.iso8601.ParseError: expected string or bytes-like object, got 'datetime.date'
If I define this field like this:
EDIT_DATE = fields.DateField(description=' Modify date ')
I can only get the date information, not the time information
If I define this field like this:
EDIT_DATE = fields.TimeField(description=' Modify date ')
The following error is reported:
ERROR: Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 693, in lifespan
async with self.lifespan_context(app) as maybe_state:
File "/usr/lib64/python3.11/contextlib.py", line 210, in aenter
return await anext(self.gen)
^^^^^^^^^^^^^^^^^^^^^
File "/home/whatsup_alarm/core/event.py", line 29, in lifespan
await get_whatsup_servers_information()
File "/home/whatsup_alarm/core/event.py", line 41, in get_whatsup_servers_information
objs = await NetDeviceSysMonitor.filter(**filter_par)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/tortoise/queryset.py", line 1151, in _execute
instance_list = await self._db.executor_class(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/tortoise/backends/base/executor.py", line 139, in execute_select
instance: "Model" = self.model._init_from_db(**dict(row_items[:current_idx]))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/tortoise/models.py", line 754, in _init_from_db
setattr(self, model_field, field.to_python_value(kwargs[key]))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/tortoise/fields/data.py", line 444, in to_python_value
if timezone.is_naive(value):
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/tortoise/timezone.py", line 84, in is_naive
return value.utcoffset() is None
^^^^^^^^^^^^^^^
AttributeError: 'datetime.date' object has no attribute 'utcoffset'
The field names in the database are all uppercase. When I use lowercase field names in the model definition, I get an error, indicating that the field name is illegal
The text was updated successfully, but these errors were encountered:
Describe the bug
I have a project that is a table created by django with a time field called models.DateTimeField that records the time in the database as follows: 2022-07-29 11:00:24.794
I created a new fastapi project, using tortoise-orm to connect to Oracle database
There are two problems:
EDIT_DATE = fields.DatetimeField(description=' Modify date ')
The following error is reported:
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 693, in lifespan
async with self.lifespan_context(app) as maybe_state:
File "/usr/lib64/python3.11/contextlib.py", line 210, in aenter
return await anext(self.gen)
^^^^^^^^^^^^^^^^^^^^^
File "/home/whatsup_alarm/core/event.py", line 29, in lifespan
await get_whatsup_servers_information()
File "/home/whatsup_alarm/core/event.py", line 41, in get_whatsup_servers_information
objs = await NetDeviceSysMonitor.filter(**filter_par)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/tortoise/queryset.py", line 1151, in _execute
instance_list = await self._db.executor_class(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/tortoise/backends/base/executor.py", line 139, in execute_select
instance: "Model" = self.model._init_from_db(**dict(row_items[:current_idx]))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/tortoise/models.py", line 754, in _init_from_db
setattr(self, model_field, field.to_python_value(kwargs[key]))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/tortoise/fields/data.py", line 354, in to_python_value
value = parse_datetime(value)
^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/iso8601/iso8601.py", line 124, in parse_date
raise ParseError(e)
iso8601.iso8601.ParseError: expected string or bytes-like object, got 'datetime.date'
If I define this field like this:
EDIT_DATE = fields.DateField(description=' Modify date ')
I can only get the date information, not the time information
If I define this field like this:
EDIT_DATE = fields.TimeField(description=' Modify date ')
The following error is reported:
ERROR: Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 693, in lifespan
async with self.lifespan_context(app) as maybe_state:
File "/usr/lib64/python3.11/contextlib.py", line 210, in aenter
return await anext(self.gen)
^^^^^^^^^^^^^^^^^^^^^
File "/home/whatsup_alarm/core/event.py", line 29, in lifespan
await get_whatsup_servers_information()
File "/home/whatsup_alarm/core/event.py", line 41, in get_whatsup_servers_information
objs = await NetDeviceSysMonitor.filter(**filter_par)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/tortoise/queryset.py", line 1151, in _execute
instance_list = await self._db.executor_class(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/tortoise/backends/base/executor.py", line 139, in execute_select
instance: "Model" = self.model._init_from_db(**dict(row_items[:current_idx]))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/tortoise/models.py", line 754, in _init_from_db
setattr(self, model_field, field.to_python_value(kwargs[key]))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/tortoise/fields/data.py", line 444, in to_python_value
if timezone.is_naive(value):
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/tortoise/timezone.py", line 84, in is_naive
return value.utcoffset() is None
^^^^^^^^^^^^^^^
AttributeError: 'datetime.date' object has no attribute 'utcoffset'
The text was updated successfully, but these errors were encountered: