Checklist
Describe the bug
I'm getting a 500 error when accessing details.
Steps to reproduce the bug
- Select the model in /admin/.
- Click view on any item.
Expected behavior
Load the view template.
Actual behavior
500 error.
Exception.
Debugging material
INFO: 127.0.0.1:63769 - "GET /file/details/c09f63a4-7093-45f6-8498-17bbcd7e40e6 HTTP/1.1" 500 Internal Server Error
ERROR: Exception in ASGI application
Traceback (most recent call last):
File "/Users/theber/code/college-toolkit/.venv/lib/python3.9/site-packages/uvicorn/protocols/http/httptools_impl.py", line 372, in run_asgi
result = await app(self.scope, self.receive, self.send)
File "/Users/theber/code/college-toolkit/.venv/lib/python3.9/site-packages/uvicorn/middleware/proxy_headers.py", line 75, in call
return await self.app(scope, receive, send)
File "/Users/theber/code/college-toolkit/.venv/lib/python3.9/site-packages/fastapi/applications.py", line 269, in call
await super().call(scope, receive, send)
File "/Users/theber/code/college-toolkit/.venv/lib/python3.9/site-packages/starlette/applications.py", line 124, in call
await self.middleware_stack(scope, receive, send)
File "/Users/theber/code/college-toolkit/.venv/lib/python3.9/site-packages/starlette/middleware/errors.py", line 184, in call
raise exc
File "/Users/theber/code/college-toolkit/.venv/lib/python3.9/site-packages/starlette/middleware/errors.py", line 162, in call
await self.app(scope, receive, _send)
File "/Users/theber/code/college-toolkit/.venv/lib/python3.9/site-packages/starlette/exceptions.py", line 93, in call
raise exc
File "/Users/theber/code/college-toolkit/.venv/lib/python3.9/site-packages/starlette/exceptions.py", line 82, in call
await self.app(scope, receive, sender)
File "/Users/theber/code/college-toolkit/.venv/lib/python3.9/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in call
raise e
File "/Users/theber/code/college-toolkit/.venv/lib/python3.9/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in call
await self.app(scope, receive, send)
File "/Users/theber/code/college-toolkit/.venv/lib/python3.9/site-packages/starlette/routing.py", line 670, in call
await route.handle(scope, receive, send)
File "/Users/theber/code/college-toolkit/.venv/lib/python3.9/site-packages/starlette/routing.py", line 418, in handle
await self.app(scope, receive, send)
File "/Users/theber/code/college-toolkit/.venv/lib/python3.9/site-packages/starlette/applications.py", line 124, in call
await self.middleware_stack(scope, receive, send)
File "/Users/theber/code/college-toolkit/.venv/lib/python3.9/site-packages/starlette/middleware/errors.py", line 184, in call
raise exc
File "/Users/theber/code/college-toolkit/.venv/lib/python3.9/site-packages/starlette/middleware/errors.py", line 162, in call
await self.app(scope, receive, _send)
File "/Users/theber/code/college-toolkit/.venv/lib/python3.9/site-packages/starlette/exceptions.py", line 93, in call
raise exc
File "/Users/theber/code/college-toolkit/.venv/lib/python3.9/site-packages/starlette/exceptions.py", line 82, in call
await self.app(scope, receive, sender)
File "/Users/theber/code/college-toolkit/.venv/lib/python3.9/site-packages/starlette/routing.py", line 670, in call
await route.handle(scope, receive, send)
File "/Users/theber/code/college-toolkit/.venv/lib/python3.9/site-packages/starlette/routing.py", line 266, in handle
await self.app(scope, receive, send)
File "/Users/theber/code/college-toolkit/.venv/lib/python3.9/site-packages/starlette/routing.py", line 65, in app
response = await func(request)
File "/Users/theber/code/college-toolkit/.venv/lib/python3.9/site-packages/sqladmin/application.py", line 286, in details
return self.templates.TemplateResponse(model_admin.details_template, context)
File "/Users/theber/code/college-toolkit/.venv/lib/python3.9/site-packages/starlette/templating.py", line 98, in TemplateResponse
return _TemplateResponse(
File "/Users/theber/code/college-toolkit/.venv/lib/python3.9/site-packages/starlette/templating.py", line 37, in init
content = template.render(context)
File "/Users/theber/code/college-toolkit/.venv/lib/python3.9/site-packages/jinja2/environment.py", line 1301, in render
self.environment.handle_exception()
File "/Users/theber/code/college-toolkit/.venv/lib/python3.9/site-packages/jinja2/environment.py", line 936, in handle_exception
raise rewrite_traceback_stack(source=source)
File "/Users/theber/code/college-toolkit/.venv/lib/python3.9/site-packages/sqladmin/templates/details.html", line 1, in top-level template code
{% extends "layout.html" %}
File "/Users/theber/code/college-toolkit/.venv/lib/python3.9/site-packages/sqladmin/templates/layout.html", line 1, in top-level template code
{% extends "base.html" %}
File "/Users/theber/code/college-toolkit/.venv/lib/python3.9/site-packages/sqladmin/templates/base.html", line 15, in top-level template code
{% block body %}
File "/Users/theber/code/college-toolkit/.venv/lib/python3.9/site-packages/sqladmin/templates/layout.html", line 49, in block 'body'
{% block content %} {% endblock %}
File "/Users/theber/code/college-toolkit/.venv/lib/python3.9/site-packages/sqladmin/templates/details.html", line 29, in block 'content'
{{ model_admin.get_detail_value(model, attr) }}
File "/Users/theber/code/college-toolkit/.venv/lib/python3.9/site-packages/sqladmin/models.py", line 592, in _url_for_details_with_attr
pk = getattr(target, attr.mapper.primary_key[0].name)
AttributeError: 'NoneType' object has no attribute 'id'
Environment
MacOSX, Python3.9, 0.1.9
Additional context
This is my models file:
# https://gist.github.com/gmolveau/7caeeefe637679005a7bb9ae1b5e421e
class GUID(TypeDecorator):
"""Platform-independent GUID type.
Uses PostgreSQL's UUID type, otherwise uses
CHAR(32), storing as stringified hex values.
"""
impl = CHAR
cache_ok = True
def load_dialect_impl(self, dialect):
if dialect.name == "postgresql":
return dialect.type_descriptor(UUID())
else:
return dialect.type_descriptor(CHAR(32))
def process_bind_param(self, value, dialect):
if value is None:
return value
elif dialect.name == "postgresql":
return str(value)
else:
if not isinstance(value, uuid.UUID):
return "%.32x" % uuid.UUID(value).int
else:
# hexstring
return "%.32x" % value.int
def _uuid_value(self, value):
if value is None:
return value
else:
if not isinstance(value, uuid.UUID):
value = uuid.UUID(value)
return value
def process_result_value(self, value, dialect):
return self._uuid_value(value)
def sort_key_function(self, value):
return self._uuid_value(value)
class ModelBase(Base):
__abstract__ = True
id = Column(GUID(), primary_key=True, default=lambda: str(uuid.uuid4()))
class File(ModelBase):
__tablename__ = "files"
name = Column(String(300), index=True)
file_id = Column(String(256), unique=True)
toolkit_id = Column(GUID(), ForeignKey("toolkits.id"), index=True)
toolkit = relationship("Toolkit", back_populates="files")