Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid UnknownTimeZoneError when creating patient from Sample #29

Merged
merged 4 commits into from
Feb 7, 2022

Conversation

ramonski
Copy link
Contributor

@ramonski ramonski commented Feb 4, 2022

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 with asdatetime 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.

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 with `asdatetime`,
which resulted in a static timezone like this:

`datetime.datetime(1980, 2, 25, 0, 0, tzinfo=<StaticTzInfo 'GMT+1'>)`
@ramonski ramonski requested a review from xispa February 4, 2022 21:24
@ramonski ramonski added the bug Something isn't working label Feb 4, 2022
@xispa xispa merged commit 47bd4f0 into master Feb 7, 2022
@xispa xispa deleted the avoid-unknown-timezone-error branch February 7, 2022 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging this pull request may close these issues.

2 participants