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

do not crash when facing unsupported calendar models #61

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ Version 0.9.0
To be released.


Version 0.8.2
-------------

Released on July 10, 2024.

- Fixing issues [:issue:`35`] and [:issue:`54`]. Returns raw time dictionaries instead of crashing when encountering unsupported calendar models [:pr:`61` by David Doukhan].


Version 0.8.0 & 0.8.1
---------------------

Expand Down
15 changes: 10 additions & 5 deletions tests/datavalue_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,16 @@ def other_value(**kwargs) -> Dict[str, object]:
with raises(DatavalueError):
d(fx_client, datatype, other_value(time=None))
# no time field
with raises(DatavalueError):
d(
fx_client, datatype,
other_value(calendarmodel='unspported calendar model')
)
# if the calendar model is unsupported, it should return
# the raw data value dictionnary
# this is a quick and temporary fix before longer term support
# of alternative calendar models (julian for instance, see issue #54)
# this fix allows the system not to crash and let API user do a custom
# management when this dictionary is returned instead
# of datetime, tuples or int
unsupported_cal = other_value(calendarmodel='unsupported calendar model')
assert d(fx_client, datatype, unsupported_cal) == unsupported_cal

with raises(DatavalueError):
d(fx_client, datatype, other_value(time='-2017-02-22T02:53:12Z'))
# only AD (CE) time is supported
Expand Down
4 changes: 2 additions & 2 deletions wikidata/datavalue.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def time(self,
client: Client,
datavalue: Mapping[str, object]) -> Union[datetime.date,
datetime.datetime,
Mapping[str, object],
Tuple[int, int],
int]:
value = datavalue['value']
Expand All @@ -160,8 +161,7 @@ def time(self,
except KeyError:
raise DatavalueError('missing "calendarmodel" field', datavalue)
if cal != 'http://www.wikidata.org/entity/Q1985727':
raise DatavalueError('{!r} is unsupported calendarmodel for time '
'datavalue'.format(cal), datavalue)
return datavalue
try:
time = value['time']
except KeyError:
Expand Down
Loading