Skip to content

Conversation

@jtrobles-cdd
Copy link
Member

@jtrobles-cdd jtrobles-cdd commented Sep 10, 2025

This pull request refactors how substring lookups are handled for Chilean RUT fields in Django filters, centralizing logic in the RutFilter class and improving test coverage.

The main change is that the selection of the form field class for substring lookups (like contains and icontains) is now handled within RutFilter.__init__(), instead of being managed by a custom filter_for_lookup() override in SiiFilterSet. This results in cleaner code and more reliable behavior.

Key changes include:

  • Refactoring and Logic Centralization:
    • Moved the logic for selecting the appropriate field_class for substring lookups (contains, icontains) from SiiFilterSet.filter_for_lookup() into the RutFilter constructor, ensuring that substring lookups use a plain CharField instead of a strict RutField that would fail on invalid substrings.
  • Test Enhancements:
    • Added comprehensive tests for RutFilter to verify that the correct field_class is chosen for each lookup expression, and for SiiFilterSet to ensure filter_for_lookup() returns filters with the correct field classes for different lookup types.

@jtrobles-cdd jtrobles-cdd self-assigned this Sep 10, 2025
@codecov
Copy link

codecov bot commented Sep 10, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.82%. Comparing base (420c517) to head (c4df64a).
⚠️ Report is 3 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #878      +/-   ##
===========================================
+ Coverage    88.70%   88.82%   +0.12%     
===========================================
  Files           38       38              
  Lines         3496     3498       +2     
  Branches       342      342              
===========================================
+ Hits          3101     3107       +6     
+ Misses         243      239       -4     
  Partials       152      152              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Refactor how substring lookups are handled for Chilean RUT fields in
Django filters, centralizing logic in the `RutFilter` class and
improving test coverage.

The main change is that the selection of the form field class for
substring lookups (like `contains` and `icontains`) is now handled
within `RutFilter.__init__()`, instead of being managed by a custom
`filter_for_lookup()` override in `SiiFilterSet`. This results in
cleaner code and more reliable behavior.

Key changes include:

- Refactoring and Logic Centralization:
  - Moved the logic for selecting the appropriate `field_class` for
    substring lookups (`contains`, `icontains`) from `SiiFilterSet.filter_for_lookup()`
    into the `RutFilter` constructor, ensuring that substring lookups
    use a plain `CharField` instead of a strict `RutField` that would
    fail on invalid substrings.
- Test Enhancements:
  - Added comprehensive tests for `RutFilter` to verify that the correct
    `field_class` is chosen for each lookup expression, and for
    `SiiFilterSet` to ensure `filter_for_lookup()` returns filters with
    the correct field classes for different lookup types.
@sonarqubecloud
Copy link

@jtrobles-cdd jtrobles-cdd added enhancement New feature or request and removed task Task or chore labels Sep 10, 2025
@jtrobles-cdd jtrobles-cdd marked this pull request as ready for review September 10, 2025 13:36
@jtrobles-cdd jtrobles-cdd requested a review from a team as a code owner September 10, 2025 13:37
@jtrobles-cdd jtrobles-cdd merged commit fdbb503 into develop Sep 10, 2025
23 checks passed
@jtrobles-cdd jtrobles-cdd deleted the improve-dj-filter-rut branch September 10, 2025 13:38
@jtrobles-cdd jtrobles-cdd mentioned this pull request Sep 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: rut enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants