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

Unexpected behavior for check_items (with respect to the doc) #69

Closed
christian-oreilly opened this issue Feb 14, 2017 · 1 comment
Closed

Comments

@christian-oreilly
Copy link

christian-oreilly commented Feb 14, 2017

In the doc, it is said :

Before calling this method, the use of check_items() is encouraged, in order to confirm that the item to be created contains only valid fields.

and then an example is provided

template = zot.item_template('book')
template['creators'][0]['firstName'] = 'Monty'
template['creators'][0]['lastName'] = 'Cantsin'
template['title'] = 'Maris Kundzins: A Life'
resp = zot.create_items([template])

If we modify this example to follow the recommendation of using check_items() as follow

template = zot.item_template('book')
template['creators'][0]['firstName'] = 'Monty'
template['creators'][0]['lastName'] = 'Cantsin'
template['title'] = 'Maris Kundzins: A Life'
zot.check_items([template])
resp = zot.create_items([template])

it crashes with

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/oreilly/.local/lib/python3.4/site-packages/pyzotero/zotero.py", line 806, in check_items
    to_check = set(i for i in list(item['data'].keys()))
KeyError: 'data'

It is not obvious how to use check_items() in conjunction with item_template() since these templates miss a bunch of fields that seems to be expected (fields that are there when used it in conjunction with items() for example).

@urschrei
Copy link
Owner

urschrei commented Feb 14, 2017

This should be fixed, and is on PyPI as 1.2.4

With regard to the additional top-level fields (u'links', u'library', u'version', u'meta', u'key') you see when you retrieve an item using e.g. items(), that's additional metadata that isn't required in order to create items, and Pyzotero checks for these keys and removes them prior to uploading, so you can round-trip retrieved items that you've modified.

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

No branches or pull requests

2 participants