Commit 22d7095d authored by Pierre-Yves David's avatar Pierre-Yves David
Browse files

[bfss] Make ``current_fs_path`` return None when an attribute has no value

current_fs_path was returning the future fspath when no value was defined.

* This does not make any sense
* This tricks the storage into believing that updating the attribute content is
  not necessary. The file was written but the attributes was not updated. as a
  result the assignement was not made.

(close #1725446)

--HG--
branch : stable
parent 195b24fe3a03
...@@ -173,13 +173,15 @@ class BytesFileSystemStorage(Storage): ...@@ -173,13 +173,15 @@ class BytesFileSystemStorage(Storage):
entity.cw_edited.edited_attribute(attr, Binary(fpath)) entity.cw_edited.edited_attribute(attr, Binary(fpath))
# Mark the old file as useless so the file will be removed at # Mark the old file as useless so the file will be removed at
# commit. # commit.
DeleteFileOp.get_instance(entity._cw).add_data(oldpath) if oldpath is not None:
DeleteFileOp.get_instance(entity._cw).add_data(oldpath)
return binary return binary
def entity_deleted(self, entity, attr): def entity_deleted(self, entity, attr):
"""an entity using this storage for attr has been deleted""" """an entity using this storage for attr has been deleted"""
fpath = self.current_fs_path(entity, attr) fpath = self.current_fs_path(entity, attr)
DeleteFileOp.get_instance(entity._cw).add_data(fpath) if fpath is not None:
DeleteFileOp.get_instance(entity._cw).add_data(fpath)
def new_fs_path(self, entity, attr): def new_fs_path(self, entity, attr):
# We try to get some hint about how to name the file using attribute's # We try to get some hint about how to name the file using attribute's
...@@ -199,13 +201,16 @@ class BytesFileSystemStorage(Storage): ...@@ -199,13 +201,16 @@ class BytesFileSystemStorage(Storage):
return fspath return fspath
def current_fs_path(self, entity, attr): def current_fs_path(self, entity, attr):
"""return the current fs_path of the tribute.
Return None is the attr is not stored yet."""
sysource = entity._cw.pool.source('system') sysource = entity._cw.pool.source('system')
cu = sysource.doexec(entity._cw, cu = sysource.doexec(entity._cw,
'SELECT cw_%s FROM cw_%s WHERE cw_eid=%s' % ( 'SELECT cw_%s FROM cw_%s WHERE cw_eid=%s' % (
attr, entity.__regid__, entity.eid)) attr, entity.__regid__, entity.eid))
rawvalue = cu.fetchone()[0] rawvalue = cu.fetchone()[0]
if rawvalue is None: # no previous value if rawvalue is None: # no previous value
return self.new_fs_path(entity, attr) return None
return sysource._process_value(rawvalue, cu.description[0], return sysource._process_value(rawvalue, cu.description[0],
binarywrap=str) binarywrap=str)
......
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