[PATCH file] Update data_name from data's filename when the former is unchanged

Denis Laxalde denis.laxalde at logilab.fr
Thu Sep 12 15:24:24 CEST 2019


# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1568294134 -7200
#      Thu Sep 12 15:15:34 2019 +0200
# Node ID 4f6c82e1e5e2e0b3a3ccf006b479d212c96113a1
# Parent  5edf2abd431af07449667a6bb5c529cbc791b0fb
# Available At https://hg.logilab.org/review/cubes/file
#              hg pull https://hg.logilab.org/review/cubes/file -r 4f6c82e1e5e2
Update data_name from data's filename when the former is unchanged

This follows up on changeset 134521c47201 which introduced the extra
check about the absence of 'data_name' in cw_edited. However, when
coming from a web form (at least as of today's behavior of cubicweb),
this field is always present leading to the if: block never being
executed.

We hence change it to only avoid override of 'data_name' if is explicitly
changed (i.e. when the "old" and "new" values differ).

Test (test_file_name_priority) introduced in aforementioned changesets
still passes.

diff --git a/cubicweb_file/entities.py b/cubicweb_file/entities.py
--- a/cubicweb_file/entities.py
+++ b/cubicweb_file/entities.py
@@ -40,8 +40,8 @@ class File(AnyEntity):
         """
         assert 'data' in self.cw_edited, "missing mandatory attribute data"
         if self.cw_edited.get('data'):
-            if (hasattr(self.data, 'filename')
-                    and not self.cw_edited.get('data_name')):
+            old, new = self.cw_edited.oldnewvalue('data_name')
+            if hasattr(self.data, 'filename') and old == new:
                 self.cw_edited['data_name'] = self.data.filename
         else:
             self.cw_edited['data_format'] = None



More information about the cubicweb-devel mailing list