I am trying to create and save the record to DynamoDB
ServiceStateModel(
instance_id=service_request["instance_id"],
plan_id=service_request["plan_id"],
service_id=service_request["service_id"],
space_id=service_request["space_guid"],
organization_id=service_request["organization_guid"],
last_operation={
'name': ServiceOperationEnum.PROVISION,
'state': ServiceStateEnum.IN_PROGRESS},
cloud_foundry={
'apps': apps,
'services': services
})\
.save()
Where apps
and services
look like this
apps = [CloudFoundryEntityAttribute(entity_id=app, state=ServiceStateEnum.IN_PROGRESS)
for app in target_profile['apps'].keys()]
services = [CloudFoundryEntityAttribute(entity_id=service, state=ServiceStateEnum.IN_PROGRESS)
for service in target_profile['services'].keys()]
I check them in logs and they are not empty or None
but contain the data I expect. However when I try to execute save
it fails with the error
File "/.../cloud.py", line 243, in deploy
'services': services
File "/usr/local/lib/python3.7/site-packages/pynamodb/models.py", line 409, in save
data = self._get_connection().put_item(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/pynamodb/connection/table.py", line 139, in put_item
return_item_collection_metrics=return_item_collection_metrics)
File "/usr/local/lib/python3.7/site-packages/pynamodb/connection/base.py", line 967, in put_item
return_item_collection_metrics=return_item_collection_metrics
File "/usr/local/lib/python3.7/site-packages/pynamodb/connection/base.py", line 859, in get_operation_kwargs
operation_kwargs.update(self.get_identifier_map(table_name, hash_key, range_key, key=key))
File "/usr/local/lib/python3.7/site-packages/pynamodb/connection/base.py", line 784, in get_identifier_map
return tbl.get_identifier_map(hash_key, range_key=range_key, key=key)
File "/usr/local/lib/python3.7/site-packages/pynamodb/connection/base.py", line 207, in get_identifier_map
self.hash_keyname: {
File "/usr/local/lib/python3.7/site-packages/pynamodb/connection/base.py", line 101, in hash_keyname
for attr in self.data.get(KEY_SCHEMA):
TypeError: 'NoneType' object is not iterable
My model
definition looks like this
class CloudFoundryEntityAttribute(MapAttribute):
entity_id = UnicodeAttribute() # effectively a name
state = UnicodeAttribute()
class CloudFoundryAttribute(MapAttribute):
services = ListAttribute(of=CloudFoundryEntityAttribute)
apps = ListAttribute(of=CloudFoundryEntityAttribute)
class CloudFoundryLastOperationAttribute(MapAttribute):
name = UnicodeAttribute()
state = UnicodeAttribute()
class ServiceStateModel(Model):
class Meta:
table_name = Config.AWS_DYNAMODB_TABLE_NAME
region = Config.AWS_DEFAULT_REGION
aws_access_key_id = Config.AWS_ACCESS_KEY_ID
aws_secret_access_key = Config.AWS_SECRET_ACCESS_KEY
instance_id = UnicodeAttribute(hash_key=True)
plan_id = UnicodeAttribute()
service_id = UnicodeAttribute()
space_id = UnicodeAttribute()
organization_id = UnicodeAttribute()
cloud_foundry = CloudFoundryAttribute()
last_operation = CloudFoundryLastOperationAttribute()
What is wrong? I presume it might be something with my attribute definition...