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

Conversation

DavidDoukhan
Copy link
Contributor

Dear Maintainer,

Here is a simple proposal for avoiding crashes in situations when unsupported calendar models are found in wikidata (see issue #54).

The minimalist strategy consist to return the raw dictionary of unsupported calendar models instead of having the program crashing.

See this entity with a Julian birthdate :

from wikidata.client import Client
client = Client()
birthdate = client.get('P569')
x = 'Q675908'
entity= client.get(x)
print(entity[birthdate])

{'value': {'time': '+1557-09-16T00:00:00Z', 'timezone': 0, 'before': 0, 'after': 0, 'precision': 11, 'calendarmodel': 'http://www.wikidata.org/entity/Q1985786'}, 'type': 'time'}

This fix do not affect entities with supported calendar models:

x = 'Q2897944'
entity= client.get(x)
print(entity[birthdate])

1951-12-02

I believe this small fix help users to define appropriate strategies when facing unsupported calendar models, instead of having the whole program crash, or having to implement alternative decoders.
Users already need to check date types that could be int, date, datetime, or tuple. They'll may understand that when it is a dictionary, they need to do appropriate processings.

Let me know if you think this proposal is useful and consistent with the philosophy of this project

Kind regards, and thanks again for this usefull framework !

Copy link
Owner

@dahlia dahlia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late response. Everything looks okay to me. Could you add an entry for it to the changelog?

@DavidDoukhan
Copy link
Contributor Author

Sorry for the late response. Everything looks okay to me. Could you add an entry for it to the changelog?

done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants