Skip to content

Conversation

@therealjozber
Copy link
Contributor

Summary

This pull request adds tests to verify that attempting to access serializer.data before calling serializer.is_valid() correctly raises an AssertionError for serializers involving relational fields.

These tests address the missing coverage noted by TODO comments in:

  • tests/test_relations_hyperlink.py
  • tests/test_relations_pk.py

Changes

  • Added test_data_cannot_be_accessed_prior_to_is_valid() to:
    • HyperlinkedManyToManyTests
    • PKManyToManyTests
  • Introduced APIRequestFactory where required to construct request instances.
  • Removed the resolved TODO markers.

Rationale

Accessing .data prior to validation is inconsistent with DRF’s serializer lifecycle expectations. These tests ensure consistent behavior across relational serializers and protect against regressions.

Testing

  • New tests pass locally.
  • All existing tests continue to pass (1612 passed, 4 skipped).
  • Pre-commit hooks passed without issues.

This PR introduces no functional changes—only test coverage improvements.

- Add test_data_cannot_be_accessed_prior_to_is_valid to HyperlinkedManyToManyTests
- Add test_data_cannot_be_accessed_prior_to_is_valid to PKManyToManyTests
- Remove TODO comments that were addressed
- Ensures AssertionError is raised when accessing .data before validation

Fixes TODO items in:
- tests/test_relations_hyperlink.py (line 71)
- tests/test_relations_pk.py (line 97)
@therealjozber
Copy link
Contributor Author

Thank you for the reviews and approval. The PR is ready to merge, and I'm available for any further adjustments if needed.

@auvipy auvipy merged commit 78db4dd into encode:main Dec 9, 2025
7 checks passed
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.

3 participants