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
The bug is reproducible against the latest release and/or master.
There are no similar issues or pull requests to fix it yet.
Describe the bug
can't read the content of the model
To reproduce
try the quickstart of the doc
import databases
import orm
import asyncio
database = databases.Database("sqlite:///db.sqlite")
models = orm.ModelRegistry(database=database)
class Note(orm.Model):
tablename = "notes"
registry = models
fields = {
"id": orm.Integer(primary_key=True),
"text": orm.String(max_length=100),
"completed": orm.Boolean(default=False),
}
# Create the database and tables
# models.create_all()
async def get_all():
data = await Note.objects.get(id=1)
print(data)
data = await Note.objects.all()
print(data)
for result in data:
print(result['id'])
asyncio.run(get_all())
11:58 $ python models_test.py
<__main__.Note object at 0x7f7dcdfc51f0>
[<__main__.Note object at 0x7f7dcdfc5760>, <__main__.Note object at 0x7f7dcdfc5820>]
Traceback (most recent call last):
File "models_test.py", line 29, in <module>
asyncio.run(get_all())
File "/usr/lib/python3.8/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
return future.result()
File "models_test.py", line 27, in get_all
print(result['id'])
TypeError: 'Note' object is not subscriptable
data = await Trigger.objects.get(id=1)
print(data)
<yeoboseyo.models.Trigger object at 0x7f997488bac0>
so then getting .all()
data = await Trigger.objects.all()
print(data)
for result in data:
print(result['id'])
[<yeoboseyo.models.Trigger object at 0x7f997488bac0>]
print(result['id'])
TypeError: 'Trigger' object is not subscriptable
Debugging material
(yeoboseyo) ✔ ~/Projects/yeoboseyo/yeoboseyo/yeoboseyo [master|✚ 6…11]
11:35 $ python app.py
여보세요 !
INFO: Started server process [25851]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: 127.0.0.1:48144 - "GET / HTTP/1.1" 200 OK
INFO: 127.0.0.1:48144 - "GET /static/call-me-hand.png HTTP/1.1" 304 Not Modified
<yeoboseyo.models.Trigger object at 0x7f6e2b64dee0>
INFO: 127.0.0.1:48144 - "GET /api/yeoboseyo/ HTTP/1.1" 500 Internal Server Error
ERROR: Exception in ASGI application
Traceback (most recent call last):
File "/home/foxmask/Projects/yeoboseyo/lib/python3.8/site-packages/uvicorn/protocols/http/h11_impl.py", line 373, in run_asgi
result = await app(self.scope, self.receive, self.send)
File "/home/foxmask/Projects/yeoboseyo/lib/python3.8/site-packages/uvicorn/middleware/proxy_headers.py", line 75, in call
return await self.app(scope, receive, send)
File "/home/foxmask/Projects/yeoboseyo/lib/python3.8/site-packages/starlette/applications.py", line 112, in call
await self.middleware_stack(scope, receive, send)
File "/home/foxmask/Projects/yeoboseyo/lib/python3.8/site-packages/starlette/middleware/errors.py", line 181, in call
raise exc
File "/home/foxmask/Projects/yeoboseyo/lib/python3.8/site-packages/starlette/middleware/errors.py", line 159, in call
await self.app(scope, receive, _send)
File "/home/foxmask/Projects/yeoboseyo/lib/python3.8/site-packages/starlette/exceptions.py", line 82, in call
raise exc
File "/home/foxmask/Projects/yeoboseyo/lib/python3.8/site-packages/starlette/exceptions.py", line 71, in call
await self.app(scope, receive, sender)
File "/home/foxmask/Projects/yeoboseyo/lib/python3.8/site-packages/starlette/routing.py", line 656, in call
await route.handle(scope, receive, send)
File "/home/foxmask/Projects/yeoboseyo/lib/python3.8/site-packages/starlette/routing.py", line 408, in handle
await self.app(scope, receive, send)
File "/home/foxmask/Projects/yeoboseyo/lib/python3.8/site-packages/starlette/routing.py", line 656, in call
await route.handle(scope, receive, send)
File "/home/foxmask/Projects/yeoboseyo/lib/python3.8/site-packages/starlette/routing.py", line 408, in handle
await self.app(scope, receive, send)
File "/home/foxmask/Projects/yeoboseyo/lib/python3.8/site-packages/starlette/routing.py", line 656, in call
await route.handle(scope, receive, send)
File "/home/foxmask/Projects/yeoboseyo/lib/python3.8/site-packages/starlette/routing.py", line 259, in handle
await self.app(scope, receive, send)
File "/home/foxmask/Projects/yeoboseyo/lib/python3.8/site-packages/starlette/routing.py", line 61, in app
response = await func(request)
File "app.py", line 43, in get_all
for result in data:
TypeError: 'Trigger' object is not iterable
Checklist
master
.Describe the bug
can't read the content of the model
To reproduce
try the quickstart of the doc
Expected behavior
I would like ORM works as before :)
Actual behavior
return object instead of data
the doc says
but I get
so then getting .all()
Debugging material
INFO: 127.0.0.1:48144 - "GET / HTTP/1.1" 200 OK
INFO: 127.0.0.1:48144 - "GET /static/call-me-hand.png HTTP/1.1" 304 Not Modified
<yeoboseyo.models.Trigger object at 0x7f6e2b64dee0>
INFO: 127.0.0.1:48144 - "GET /api/yeoboseyo/ HTTP/1.1" 500 Internal Server Error
ERROR: Exception in ASGI application
Traceback (most recent call last):
File "/home/foxmask/Projects/yeoboseyo/lib/python3.8/site-packages/uvicorn/protocols/http/h11_impl.py", line 373, in run_asgi
result = await app(self.scope, self.receive, self.send)
File "/home/foxmask/Projects/yeoboseyo/lib/python3.8/site-packages/uvicorn/middleware/proxy_headers.py", line 75, in call
return await self.app(scope, receive, send)
File "/home/foxmask/Projects/yeoboseyo/lib/python3.8/site-packages/starlette/applications.py", line 112, in call
await self.middleware_stack(scope, receive, send)
File "/home/foxmask/Projects/yeoboseyo/lib/python3.8/site-packages/starlette/middleware/errors.py", line 181, in call
raise exc
File "/home/foxmask/Projects/yeoboseyo/lib/python3.8/site-packages/starlette/middleware/errors.py", line 159, in call
await self.app(scope, receive, _send)
File "/home/foxmask/Projects/yeoboseyo/lib/python3.8/site-packages/starlette/exceptions.py", line 82, in call
raise exc
File "/home/foxmask/Projects/yeoboseyo/lib/python3.8/site-packages/starlette/exceptions.py", line 71, in call
await self.app(scope, receive, sender)
File "/home/foxmask/Projects/yeoboseyo/lib/python3.8/site-packages/starlette/routing.py", line 656, in call
await route.handle(scope, receive, send)
File "/home/foxmask/Projects/yeoboseyo/lib/python3.8/site-packages/starlette/routing.py", line 408, in handle
await self.app(scope, receive, send)
File "/home/foxmask/Projects/yeoboseyo/lib/python3.8/site-packages/starlette/routing.py", line 656, in call
await route.handle(scope, receive, send)
File "/home/foxmask/Projects/yeoboseyo/lib/python3.8/site-packages/starlette/routing.py", line 408, in handle
await self.app(scope, receive, send)
File "/home/foxmask/Projects/yeoboseyo/lib/python3.8/site-packages/starlette/routing.py", line 656, in call
await route.handle(scope, receive, send)
File "/home/foxmask/Projects/yeoboseyo/lib/python3.8/site-packages/starlette/routing.py", line 259, in handle
await self.app(scope, receive, send)
File "/home/foxmask/Projects/yeoboseyo/lib/python3.8/site-packages/starlette/routing.py", line 61, in app
response = await func(request)
File "app.py", line 43, in get_all
for result in data:
TypeError: 'Trigger' object is not iterable
Environment
Additional context
the same code worked in 0.1.8 (https://framagit.org/annyong/yeoboseyo/-/blob/master/yeoboseyo/models.py)
The text was updated successfully, but these errors were encountered: