CMFCategory: keep only the first occurrence of each category while preserving order.
-
Owner
Shouldn't we make a special setter for that ? a bit like
set{Category}ValueSet
but preserving the order ? -
Owner
( I guess there are code depending on the ability to set duplicates categories, but I don't know examples of specific cases )
-
Owner
I cannot imagine any usecase where we need to store duplicate category relations intentionally... and that cannot be represented on catalog. Do you really want to support such functionality ?
-
Owner
That's true that it's not supported by catalog. I don't know such a use case either, but I see we have
Set
getters and setter and I guess we added them for the purpose of controlling presence of duplicates, so probably there's a reason to allow duplicates. If we disallow duplicates at CMFActivity level ,Set
getters becomes a useless. -
Owner
In my opinion,
Set
setter is badly implemented because it does not guarantee the order of values thusDefault
getter value is not predictable. As a part of this change,Set
getter / setter should become an alias of normalList
getter / setter. -
Owner
Well, if
Set
-type getter returns aset
, it is anyway non-ordered object in Python, thus the order of the return value is unpredictable and I feel it is useless. Or shouldSet
-type getter return alist
or atuple
(keeping the order but having no duplicate) that sounds a bit strange ?I'm still wondering if we REALLY have a strong requirement to store duplicate category relations. Anybody @nexedi has ?
Anyway current
Set
-type accessors are bad because :-
Set
-type setter does not preserve the order when stroging intocategories
property. -
Set
-type getter does not preserve the order stored incategories
property.
BTW, the reason why I only modified setter in this commit is for the performance, i.e. we can assume that getters are much more often called than setters and once setter is well implemented to remove duplicate, we don't need to remove duplicate in getter.
-
-
Owner
Do we really use
set
accessors? Since the order of categories is necessary to determine the default value andset
is unordered,set
is simply incompatible with ERP5 category system. No? -
Owner
Or should Set-type getter return a
list
or atuple
(keeping the order but having no duplicate) that sounds a bit strange ?To me it is not so strange, I understand these accessor qualificators as expectations on the semantic level rather than on type level: a
Set
setter should accept any vector and may complain when finding duplicate values (or silently discard all but one, but then we need to specify which is kept). Another example is thatList
getter could return a tuple if it wants, IMHO.But besides this, I agree with @kazuhiko that the point here is whether we have a use-case of multiple all-identical relationships on documents. If there is none, then I think related API should either discard duplicates (again, specifying which is kept) or complain on duplicates (I tend to prefer the latter). Accepting meaningless garbage is only asking for trouble later:
- maybe when some other change will suddenly cause the shadowed entry to become significant
- maybe when another modification codepath will trash all but one (ex: set 2 source relations to the same document on a document with a monovalued my_source field, then change the value in that field, bam both relations are replaced with a single new one to the new source).
Do note that "all-identical" is a critically important part in my argument:
- same base category
- same related document
-
Owner
-
Set
-type getter ALREADY returns alist
instance, not aset
instance. So the issue is just 'it is unordered'. -
Set
-type setter has hardcodedkeep_default=1
. Even if we keep this behaviour, I think we should keep the order in the rest. - possible usage of 'duplicate' categories is representing 'steps' like ('xxx/step1', 'xxx/step2', 'xxx/step1', 'xxx/step3'), according to @jp
So I created a new merge request !862 (merged).
-
-
mentioned in merge request !862 (merged)