Skip to content

Conversation

harshalkalewar
Copy link

@harshalkalewar harshalkalewar commented Aug 20, 2025

Fixes #1109

This PR fixes handling of the included array so that it correctly respects both JSONAPIMeta.included_resources defaults and explicit include query parameters.

Description of the Change

  • Simplified the renderers.py logic to handle empty included arrays correctly using if included_resources:.
  • Added and adjusted test cases in test_includes.py to verify:
  • Updated failing test_search_keywords to expect an empty included array in line with default includes

Checklist

  • PR only contains one change (considered splitting up PR)
  • unit-test added
  • documentation updated
  • CHANGELOG.md updated (only for user relevant changes)
  • author name in AUTHORS

Fixes django-json-api#1109. Ensures top-level 'included' is returned as [] when the query param
?include= is provided but no related resources exist. Updates integration tests
to reflect JSON:API v1.1 spec compliance.
@harshalkalewar
Copy link
Author

Fixed tox lint config issue. Also, verified locally with tox -e lint and all checks passing.

Copy link
Member

@sliverc sliverc left a comment

Choose a reason for hiding this comment

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

Thanks for working on this PR.

I would recommend being careful when you use AI. Always verify what it does, before accepting it.

For instance the pull request template and its checklist is actually made for human beings and not AI.

In the checklist it states to add changelog entry and add yourself to authors. Great if you could follow up on those.

Let me know if you have any questions.

.gitignore Outdated
@@ -43,6 +43,9 @@ coverage.xml

# VirtualEnv
.venv/
venv/
Copy link
Member

Choose a reason for hiding this comment

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

Please revert changes to .gitignore. The DJA documentation states to use env folder. Actually .venv is already additional, I want to avoid that we add more.

In case you want to use venv naming locally, you can always ignore it in your local in the file .git/info/exclude.

.gitignore Outdated
@@ -51,3 +54,7 @@ manage.py

# example database
drf_example

pytest.ini
Copy link
Member

Choose a reason for hiding this comment

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

not sure why this is added please revert.

@@ -659,6 +659,10 @@ def render(self, data, accepted_media_type=None, renderer_context=None):
render_data["included"].append(
included_cache[included_type][included_id]
)
else:
Copy link
Member

Choose a reason for hiding this comment

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

there is actually another feature with includes resources by default which was not mentioned in the original issues, but also needs to be considered when deciding whether an empty include array should be added or not.

Actually the whole code can be simplified. This else is not needed but in case the if needs to be adjusted to

if included_resources:

this will cover the cases of includes per default and per request query param as well.

setup.cfg Outdated
@@ -20,8 +20,9 @@ exclude =
build/lib,
.eggs
.tox,
env
.venv
env,
Copy link
Member

Choose a reason for hiding this comment

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

as mentioned above please revert.

tox.ini Outdated
@@ -47,3 +47,6 @@ deps =
-rrequirements/requirements-documentation.txt
commands =
sphinx-build -W -b html -d docs/_build/doctrees docs docs/_build/html

Copy link
Member

Choose a reason for hiding this comment

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

not so sure what empty lines shoud be fixed here? I have the feeling they rather should be reverted.

@harshalkalewar
Copy link
Author

Thanks for the feedback @sliverc. I’ll make sure to review my changes instead of relying on AI.
Regarding the failing test i.e. test_search_keywords, i noticed it fails because included: [] is now always present. should i update the test to match this new behavior, or should i adjust the implementation to keep the previous behavior?

@sliverc
Copy link
Member

sliverc commented Aug 26, 2025

Thanks for following up. You need to adjust the test_search_keywords test because this test relies on a view which has default included resources, so there should be an empty-included array.

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.

JSON API 1.1: return included array even if nothing is included
2 participants