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

Wondering whyurl field is no longer present in serializers using therest_framework_json_api.JSONRenderer#1233

Answeredbysliverc
Sam-Macpherson asked this question inQ&A
Discussion options

Up until release 7.0.0 in our project we were specifyingurl (just a manually-populatedmodels.URLField(blank=True, null=True) field on our model) in some of our DRF serializers. Using JSONRenderer as the default renderer in our settings:

"DEFAULT_RENDERER_CLASSES": ("rest_framework_json_api.renderers.JSONRenderer",),

We noticed that the URL field was no longer being included in the responses from our endpoints, and I tracked it down to this diff:
https://github.com/django-json-api/django-rest-framework-json-api/pull/1221/files#diff-52135bfc77d9d40d99d5451d1c64e64d75f0ae5bd338162064891dfcfc27b3b0R78

I'm just hoping to get more information on what the intent behind that change was, and what a suitable workaround would be for us. Didn't want to file a bug since it seems like an intentional change.

You must be logged in to vote

Thanks for bringing this up. The URL field is tricky. It is actually a reserved field used byHyperlinkedModelSerializer to define the identity location. The name can actually be configured withURL_FIELD_NAME which is per defaulturl. This URL field is used in JSON:API as aself-link. That it is why the URL is excluded in attributes.

However it should actually only be excluded if it is a URL field name and of typeHyperlinkedIdentityField. So this is a regression.

I will have a look and see how easy it is to fix also considering that sparse fields should handle URL as a field if it is overwritten as you do it (that was the initial change, which caused this regression).

What you can do as…

Replies: 1 comment

Comment options

Thanks for bringing this up. The URL field is tricky. It is actually a reserved field used byHyperlinkedModelSerializer to define the identity location. The name can actually be configured withURL_FIELD_NAME which is per defaulturl. This URL field is used in JSON:API as aself-link. That it is why the URL is excluded in attributes.

However it should actually only be excluded if it is a URL field name and of typeHyperlinkedIdentityField. So this is a regression.

I will have a look and see how easy it is to fix also considering that sparse fields should handle URL as a field if it is overwritten as you do it (that was the initial change, which caused this regression).

What you can do as a simple workaround is settingURL_FIELD_NAME to a different name thanurl e.g.self or similar and the URL should appear again in attributes.

You must be logged in to vote
0 replies
Answer selected bySam-Macpherson
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
2 participants
@Sam-Macpherson@sliverc

[8]ページ先頭

©2009-2025 Movatter.jp