[bfss] Make ``current_fs_path`` return None when an attribute has no value stable
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Mon, 30 May 2011 16:16:19 +0200
branchstable
changeset 7449 5e45e32071aa
parent 7448 195b24fe3a03
child 7450 c21d845836e4
[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)
server/sources/storages.py
--- a/server/sources/storages.py	Mon May 30 17:43:29 2011 +0200
+++ b/server/sources/storages.py	Mon May 30 16:16:19 2011 +0200
@@ -173,13 +173,15 @@
             entity.cw_edited.edited_attribute(attr, Binary(fpath))
             # Mark the old file as useless so the file will be removed at
             # commit.
-            DeleteFileOp.get_instance(entity._cw).add_data(oldpath)
+            if oldpath is not None:
+                DeleteFileOp.get_instance(entity._cw).add_data(oldpath)
         return binary
 
     def entity_deleted(self, entity, attr):
         """an entity using this storage for attr has been deleted"""
         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):
         # We try to get some hint about how to name the file using attribute's
@@ -199,13 +201,16 @@
         return fspath
 
     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')
         cu = sysource.doexec(entity._cw,
                              'SELECT cw_%s FROM cw_%s WHERE cw_eid=%s' % (
                              attr, entity.__regid__, entity.eid))
         rawvalue = cu.fetchone()[0]
         if rawvalue is None: # no previous value
-            return self.new_fs_path(entity, attr)
+            return None
         return sysource._process_value(rawvalue, cu.description[0],
                                        binarywrap=str)