Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Release 7.0.0 breaks sparse fields request #1228

Closed
Labels
@n2ygk

Description

@n2ygk

Description of the Bug Report

As of release 7.0.0 a sparse fields request throws a KeyError forurl at

ifapi_settings.URL_FIELD_NAMEinresourceandisinstance(
fields[api_settings.URL_FIELD_NAME],relations.RelatedField
This was working up through release 6.1.0.

I expect that this is related to this change identified in the CHANGELOG:

* Adjusted that sparse fields properly removes meta fields when not defined.

How to reproduce:

git clone https://github.com/columbia-it/django-jsonapi-trainingcd django-jsonapi-trainingpython -m venv venvsource venv/bin/activatepip install -r requirements.txtpip freeze | grep json# see the version is djangorestframework-jsonapi==7.0.0./manage.py migrate./manage.py loaddata myapp/fixtures/*yamlopenssl genrsa -out oidc.key 4096OIDC_RSA_PRIVATE_KEY_FILE=oidc.key ./manage.py runserver

Use Postman with OAuth2 asdescribed here:

Token Name: *pick a name*Grant Type: Authorization Code (With PKCE)Callback URL: https://www.getpostman.com/oauth2/callbackAuth URL: http://localhost:8000/authorize/Access Token URL: http://localhost:8000/token/Client ID: demo_djt_web_clientClient Secret: demo_djt_web_secretScope: auth-columbia demo-djt-sla-bronze read openid profile email https://api.columbia.edu/scope/groupClient Authentication: Send as Basic Auth header

ClickGet New Access Token and login as useradmin passadmin123 andAuthorize then proceed andUse Token

Send GEThttp://localhost:8000/v1/courses/?fields[courses]=course_name

observe this error:

  File "/Users/ac45/src/django-jsonapi-training/venv/lib/python3.12/site-packages/rest_framework_json_api/renderers.py", line 486, in build_json_resource_obj    fields[api_settings.URL_FIELD_NAME], relations.RelatedField    ~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^KeyError: 'url'

Then send GEThttp://localhost:8000//v1/courses/?fields[courses]=course_name,url

and get back a correct JSONAPI response.

Now ^C the runserver, downgrade to v6.1.0, and try again.

pip install djangorestframework-jsonapi==6.1.0OIDC_RSA_PRIVATE_KEY_FILE=oidc.key ./manage.py runserverSend GET http://localhost:8000/v1/courses/?fields[courses]=course_nameand get back a correct JSONAPI response.## Checklist- [x] Certain that this is a bug (if unsure or you have a question use [discussions](https://github.com/django-json-api/django-rest-framework-json-api/discussions) instead)- [x] Code snippet or unit test added to reproduce bug

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp