PynamoDB
PynamoDB copied to clipboard
MapAttribute troubles
Hello, I have some troubles using PynamoDB's MapAttribute My models looks like this:
class UserModel(Model):
class Meta:
table_name = f'user_info-{settings.stage}'
region = 'eu-central-1'
id = UnicodeAttribute(hash_key=True)
dremio = DremioMap(null=True)
class DremioMap(MapAttribute):
acknowledgment: AcknowledgmentMap()
certificate: CertificateMap()
class CertificateMap(MapAttribute):
certificate_location: UnicodeAttribute()
certificate_date: UnicodeAttribute()
class AcknowledgmentMap(MapAttribute):
acknowledgment: UnicodeAttribute()
acknowledgment_date: UnicodeAttribute()
I get an ValueError: Attribute certificate_location specified does not exist when I try to instantiate CertificateMap in the following method:
async def add_dremio(user_id: str, certificate_path: str, acknowledgment_content: str):
current_date = date.today().isoformat()
user = UserModel.get(user_id)
certificate = CertificateMap(certificate_location=certificate_path,
certificate_date=current_date)
acknowledgment = AcknowledgmentMap(acknowledgment=acknowledgment_content,
acknowledgment_date=current_date)
dremio = DremioMap(acknowledgment=acknowledgment, certificate=certificate)
user.update(actions=[UserModel.dremio.set(dremio)])
user = UserModel.get(user_id)
return user
Traceback:
Traceback (most recent call last):
File "/data/alex/git/python-microservices/api-user-info/.venv/lib/python3.9/site-packages/uvicorn/protocols/http/h11_impl.py", line 396, in run_asgi
result = await app(self.scope, self.receive, self.send)
File "/data/alex/git/python-microservices/api-user-info/.venv/lib/python3.9/site-packages/uvicorn/middleware/proxy_headers.py", line 45, in __call__
return await self.app(scope, receive, send)
File "/data/alex/git/python-microservices/api-user-info/.venv/lib/python3.9/site-packages/fastapi/applications.py", line 199, in __call__
await super().__call__(scope, receive, send)
File "/data/alex/git/python-microservices/api-user-info/.venv/lib/python3.9/site-packages/starlette/applications.py", line 111, in __call__
await self.middleware_stack(scope, receive, send)
File "/data/alex/git/python-microservices/api-user-info/.venv/lib/python3.9/site-packages/starlette/middleware/errors.py", line 181, in __call__
raise exc from None
File "/data/alex/git/python-microservices/api-user-info/.venv/lib/python3.9/site-packages/starlette/middleware/errors.py", line 159, in __call__
await self.app(scope, receive, _send)
File "/data/alex/git/python-microservices/api-user-info/.venv/lib/python3.9/site-packages/starlette/exceptions.py", line 82, in __call__
raise exc from None
File "/data/alex/git/python-microservices/api-user-info/.venv/lib/python3.9/site-packages/starlette/exceptions.py", line 71, in __call__
await self.app(scope, receive, sender)
File "/data/alex/git/python-microservices/api-user-info/.venv/lib/python3.9/site-packages/starlette/routing.py", line 566, in __call__
await route.handle(scope, receive, send)
File "/data/alex/git/python-microservices/api-user-info/.venv/lib/python3.9/site-packages/starlette/routing.py", line 227, in handle
await self.app(scope, receive, send)
File "/data/alex/git/python-microservices/api-user-info/.venv/lib/python3.9/site-packages/starlette/routing.py", line 41, in app
response = await func(request)
File "/data/alex/git/python-microservices/api-user-info/.venv/lib/python3.9/site-packages/fastapi/routing.py", line 201, in app
raw_response = await run_endpoint_function(
File "/data/alex/git/python-microservices/api-user-info/.venv/lib/python3.9/site-packages/fastapi/routing.py", line 148, in run_endpoint_function
return await dependant.call(**values)
File "/data/alex/git/python-microservices/api-user-info/src/resources/users/router.py", line 36, in post_dremio
certificate = CertificateMap(certificate_location=location,
File "/data/alex/git/python-microservices/api-user-info/.venv/lib/python3.9/site-packages/pynamodb/attributes.py", line 826, in __init__
AttributeContainer.__init__(self, **attributes)
File "/data/alex/git/python-microservices/api-user-info/.venv/lib/python3.9/site-packages/pynamodb/attributes.py", line 278, in __init__
self._set_attributes(**attributes)
File "/data/alex/git/python-microservices/api-user-info/.venv/lib/python3.9/site-packages/pynamodb/attributes.py", line 960, in _set_attributes
super()._set_attributes(**attrs)
File "/data/alex/git/python-microservices/api-user-info/.venv/lib/python3.9/site-packages/pynamodb/attributes.py", line 337, in _set_attributes
raise ValueError("Attribute {} specified does not exist".format(attr_name))
ValueError: Attribute certificate_location specified does not exist