Avoid UnknownTimeZoneError when creating patient from Sample #29
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of the issue/feature this PR addresses
Please merge senaite/senaite.core#1931 first
The code of this PR has changed to rely only on the setter from the datetime field.
This PR avoids that the following traceback occurs:
Traceback:
Traceback (innermost last):
Module ZServer.ZPublisher.Publish, line 144, in publish
Module ZPublisher.mapply, line 85, in mapply
Module ZServer.ZPublisher.Publish, line 44, in call_object
Module senaite.app.listing.view, line 223, in call
Module senaite.app.listing.ajax, line 109, in handle_subpath
Module senaite.core.decorators, line 20, in decorator
Module senaite.app.listing.decorators, line 63, in wrapper
Module senaite.app.listing.decorators, line 50, in wrapper
Module senaite.app.listing.decorators, line 100, in wrapper
Module senaite.app.listing.ajax, line 432, in ajax_folderitems
Module senaite.app.listing.decorators, line 88, in wrapper
Module senaite.app.listing.ajax, line 313, in get_folderitems
Module senaite.app.listing.view, line 937, in folderitems
Module senaite.patient.browser.patientfolder, line 116, in folderitem
Module bika.lims.api, line 444, in get_url
Module bika.lims.api, line 268, in is_brain
Module ZODB.Connection, line 795, in setstate
Module ZODB.serialize, line 633, in setGhostState
Module ZODB.serialize, line 626, in getState
Module pytz, line 307, in _p
Module pytz.tzinfo, line 539, in unpickler
Module pytz, line 188, in timezone
UnknownTimeZoneError: (UnknownTimeZoneError('GMT+1',), <function _p at 0x10adda450>, ('GMT+1',))
This happens when a
DateTime
object was converted withasdatetime
and set to the DX datetime field, which resulted in a static timezone like this:datetime.datetime(1980, 2, 25, 0, 0, tzinfo=<StaticTzInfo 'GMT+1'>)
Current behavior before PR
After instance restart, the patient object could not be deserialized anymore
Desired behavior after PR is merged
Valid
datetime
object is set as birthdate--
I confirm I have tested this PR thoroughly and coded it according to PEP8
and Plone's Python styleguide standards.