'str' object has no attribute 'toordinal'
See original GitHub issueDescribe the bug Hi!
After the latest update (0.10.24), it looks like querying for dates, using strings, is no longer working.
- My field is of type
ormar.Date(nullable=True). - Calling
await MyModel.objects.get(field=value)fails when the value is'2022-01-20' - Calling
await MyModel.objects.get(field=parse_date(value))works when the value is ^
Querying with the plain string value worked before (on 10.23).
Stack trace
../../.virtualenvs/project/lib/python3.10/site-packages/ormar/queryset/queryset.py:948: in get
return await self.filter(*args, **kwargs).get()
../../.virtualenvs/project/lib/python3.10/site-packages/ormar/queryset/queryset.py:968: in get
rows = await self.database.fetch_all(expr)
../../.virtualenvs/project/lib/python3.10/site-packages/databases/core.py:149: in fetch_all
return await connection.fetch_all(query, values)
../../.virtualenvs/project/lib/python3.10/site-packages/databases/core.py:271: in fetch_all
return await self._connection.fetch_all(built_query)
../../.virtualenvs/project/lib/python3.10/site-packages/databases/backends/postgres.py:174: in fetch_all
rows = await self._connection.fetch(query_str, *args)
../../.virtualenvs/project/lib/python3.10/site-packages/asyncpg/connection.py:601: in fetch
return await self._execute(
../../.virtualenvs/project/lib/python3.10/site-packages/asyncpg/connection.py:1639: in _execute
result, _ = await self.__execute(
../../.virtualenvs/project/lib/python3.10/site-packages/asyncpg/connection.py:1664: in __execute
return await self._do_execute(
../../.virtualenvs/project/lib/python3.10/site-packages/asyncpg/connection.py:1711: in _do_execute
result = await executor(stmt, None)
asyncpg/protocol/protocol.pyx:183: in bind_execute
???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> ???
E asyncpg.exceptions.DataError: invalid input for query argument $2: '2022-01-20' ('str' object has no attribute 'toordinal')
Let me know if you want me to try and create a reproducible example. I thought I would open the issue first, in case you immediately knew what might have changed.
Thanks for maintaining the package! 👏
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Error 'str' object has no attribute 'toordinal' in PySpark
This issue means that you are adding a Schema that don't belongs to the data. The issue: AttributeError: 'str' object has no attribute ......
Read more >AttributeError: 'str' object has no attribute 'toordinal'
I just tried running the multi-data strategy example on jupyter notebook multi example and there is this error which I am not able...
Read more >Error 'str' object has no attribute 'toordinal' in PySpark - iTecNote
This issue means that you are adding a Schema that don't belongs to the data. ... Means that you want to cast your...
Read more >Attribute:str object has no attribute 'toordinal' : r/flask - Reddit
Hey guys!! I'm trying to compare two dates but I'm getting error Attribute:str object has no attribute 'toordinal' Here's my function.
Read more >Error 'str' object has no attribute 'toordinal' in asyncpg-postgresql
You are passing a string to a date field. SQLAlchmey is looking for a date object to be passed in, hence the '('str'...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It looks like
aiopghandled the date casting like before. I’ll use this for a bit and report back, but looks good 👍Yes, unfortunately it would break complex types, it was also using not really safe literal binds docs. Although I was re-parsing it to sqlalchemy text clause you couldn’t inject SQL it was still against best practices, and was only working for simple types (didn’t work for example with dates, I had to dump them to isoformat string, which in turn was breaking the timezones 😱 )
As a quick workaround can you try the other driver from databases? Maybe it’s more permissive (aiopg instead of asyncpg)? Or maybe that needs to be fixed in databases itself, will check that.