Commit d89d0fcc authored by Elouan Martinet's avatar Elouan Martinet
Browse files

[storages] When an attribute is None, do not delete a new S3 key

parent 7b14f47ade14
Pipeline #25920 passed with stage
in 3 minutes and 13 seconds
......@@ -74,6 +74,8 @@ class S3Storage(Storage):
binary = entity.cw_edited.pop(attr)
if binary is not None:
key = self.get_s3_key(entity, attr)
if key is None:
key = self.new_s3_key(entity, attr)
# save S3 key
entity.cw_edited.edited_attribute(
attr, Binary(key.encode('utf-8')))
......@@ -100,6 +102,9 @@ class S3Storage(Storage):
"""an entity using this storage for attr has been deleted"""
if entity._cw.repo.config['s3-auto-delete']:
key = self.get_s3_key(entity, attr)
if key is None:
# no key to remove
return
self.info('Deleting object %s.%s (%s/%s) from S3',
entity.eid, attr, self.bucket, key)
resp = self.s3cnx.delete_object(Bucket=self.bucket, Key=key)
......@@ -143,7 +148,7 @@ class S3Storage(Storage):
if PY3:
key = key.decode('utf-8')
return key
return self.new_s3_key(entity, attr)
return None
def new_s3_key(self, entity, attr):
"""Generate a new key for given entity attr.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment