credential: stop using deprecated property for email
In 44e0b22f (Move to new API, detailed properties take precedence, 2011-09-09) we introduce a new data model for coordinates, in the case of emails, we have "url_string" fro the "detailed" form and "coordinate_text", for the "store what user entered" form. In some places of erp5_credential, we use setDefaultEmailText, which calls Coordinate.setText which uses the deprecated Coordinate.fromText, which sets the same value for "url_string" and "coordinate_text", which seems a questionable behavior, because the data is saved twice and some code might be using the wrong property. This changes every usage to the new coordinate_text property
-
Owner
@jerome in many cases (and in existing documents), we set the email address with
setDefaultEmailText()
and this change introduces compatibility issues.ipdb> person = self.portal.person_module.newContent(portal_type='Person') ipdb> person.setDefaultEmailText('foo@example.com') # we set email address like this in existing documents ipdb> person.default_email.url_string 'foo@example.com' ipdb> person.default_email.coordinate_text 'foo@example.com' ipdb> person.setDefaultEmailCoordinateText('bar@example.com') # this is credential update behaviour with this commit ipdb> person.default_email.url_string # this property is not updated 'foo@example.com' ipdb> person.default_email.coordinate_text 'bar@example.com' ipdb> person.getDefaultEmailText() # we still use this getter in many places, that returns the old value 'foo@example.com' ipdb> person.getDefaultEmailCoordinateText() 'bar@example.com'
Do you mean we should update all getter/setter for email address in each project ?
-
Owner
Oh sorry, I did not consider the case of persons with an existing email address set as url string, thanks. This seems a big problem, because using
erp5_credential
with such emails does not update the email.Is it also your understanding that we want to use
coordinate_text
for new emails and thaturl_string
is only for old documents ? When editing a person withPerson_view
,coordinate_text
(only) is set. On very very old emails,url_string
only is set (because before 44e0b22f there was nocoordinate_text
). On emails created witherp5_credential
before this change - and more generally every timesetText
was called, both properties are set (setText
callsfromText
andfromText
sets both ). When both are set, the UI andgetText
returnurl_string
and editing with UI editsurl_string
and the two properties become out of sync, which is the reason why I made this change, in a project data warehouse, email'sgetCoordinateText
was used. I think in ERP5 everything usessetCoordinateText
except here, I ran a script to compare allurl_string
andcoordinate_text
and only one was inconsistent, because oferp5_credential
.When making this change, I was thinking we should always use
getText
when getting, becausegetText
returnsurl_string
if set andcoordinate_text
otherwise (it usesasText
) - in my case there was also a bug in the datawarehouse code, it should be usinggetText
instead ofgetCoordinateText
to support both data models. But I did not consider the case of setting the value: whenurl_string
is set, we want to editurl_string
and only when it's not set we want to editcoordinate_text
.I think this
fromText
could be made more clever, it's deprecated and I was scared of breaking something by changing it. I am now thinking of changing to something like this - and changingerp5_credential
to use this same logic (maybe not using this method directly because it is deprecated):security.declareProtected(Permissions.ModifyPortalContent, 'fromText') @deprecated def fromText(self, text): """ Sets url_string a.k.a. scheme-specific-part of a URL """ if self.isDetailed(): self.setUrlString(text) else: self.setCoordinateText(text)
or maybe even like this:
security.declareProtected(Permissions.ModifyPortalContent, 'fromText') @deprecated def fromText(self, text): """ Sets url_string a.k.a. scheme-specific-part of a URL """ if self.isDetailed(): self.setUrlString(text) # In the past, using fromText was setting the value in both # coordinate_text and url_string properties, we remove the # duplication. self.setCoordinateText('') else: self.setCoordinateText(text)
what do you think ?