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

Cannot get resources without attributes (only with relations) #25

Closed
ngseer opened this issue Jan 28, 2019 · 2 comments
Closed

Cannot get resources without attributes (only with relations) #25

ngseer opened this issue Jan 28, 2019 · 2 comments

Comments

@ngseer
Copy link

ngseer commented Jan 28, 2019

Client fails to process response without "attributes" field. Here's the trace:

Traceback (most recent call last):
  File "<input>", line 10, in <module>
  File "/usr/lib64/python3.7/asyncio/base_events.py", line 584, in run_until_complete
    return future.result()
  File "<input>", line 7, in get_resource
  File "/home/seer/.local/share/virtualenvs/pbJ32E1R/lib/python3.7/site-packages/jsonapi_client/session.py", line 345, in _get_async
    return await self.fetch_document_by_url_async(url)
  File "/home/seer/.local/share/virtualenvs/pbJ32E1R/lib/python3.7/site-packages/jsonapi_client/session.py", line 466, in fetch_document_by_url_async
    await self._ext_fetch_by_url_async(url))
  File "/home/seer/.local/share/virtualenvs/pbJ32E1R/lib/python3.7/site-packages/jsonapi_client/session.py", line 474, in _ext_fetch_by_url_async
    return self.read(json_data, url)
  File "/home/seer/.local/share/virtualenvs/pbJ32E1R/lib/python3.7/site-packages/jsonapi_client/session.py", line 402, in read
    no_cache=no_cache)
  File "/home/seer/.local/share/virtualenvs/pbJ32E1R/lib/python3.7/site-packages/jsonapi_client/document.py", line 65, in __init__
    super().__init__(session, json_data)
  File "/home/seer/.local/share/virtualenvs/pbJ32E1R/lib/python3.7/site-packages/jsonapi_client/common.py", line 74, in __init__
    self._handle_data(data)
  File "/home/seer/.local/share/virtualenvs/pbJ32E1R/lib/python3.7/site-packages/jsonapi_client/document.py", line 88, in _handle_data
    self.resources.extend([ResourceObject(self.session, i) for i in data])
  File "/home/seer/.local/share/virtualenvs/pbJ32E1R/lib/python3.7/site-packages/jsonapi_client/document.py", line 88, in <listcomp>
    self.resources.extend([ResourceObject(self.session, i) for i in data])
  File "/home/seer/.local/share/virtualenvs/pbJ32E1R/lib/python3.7/site-packages/jsonapi_client/resourceobject.py", line 337, in __init__
    super().__init__(session, data)
  File "/home/seer/.local/share/virtualenvs/pbJ32E1R/lib/python3.7/site-packages/jsonapi_client/common.py", line 74, in __init__
    self._handle_data(data)
  File "/home/seer/.local/share/virtualenvs/pbJ32E1R/lib/python3.7/site-packages/jsonapi_client/resourceobject.py", line 410, in _handle_data
    self._attributes = AttributeDict(data=data['attributes'],
KeyError: 'attributes'

It seems that client assumes "attributes" field always exists in a server response JSON. But in according with JSONAPI spec "attributes" field is optional and, depending on inplementation, may be omitted by server for resources that don't contain any attributes.

@felnne
Copy link

felnne commented Apr 29, 2019

I have this problem as well.

WilliamMcCumstie added a commit to openflighthpc/flight-action-api that referenced this issue Jan 27, 2020
This is actually to resolve a client side bug. Ideally the
library will be fixed, but we can't have everything :/

qvantel/jsonapi-client#25
@ajjn
Copy link
Contributor

ajjn commented Feb 14, 2020

Fixed so closing this issue.

@ajjn ajjn closed this as completed Feb 14, 2020
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

3 participants