openwisp-utils icon indicating copy to clipboard operation
openwisp-utils copied to clipboard

[change] Migrate from django-admin-autocomplete-filter to dalf #582

Open SAMurai-16 opened this issue 10 months ago β€’ 11 comments

Replace the unmaintained and license-incompatible django-admin-autocomplete-filter with django-admin-list-filter (dalf), an actively maintained MIT-licensed alternative that uses Django's native admin autocomplete infrastructure.

Changes:

  • Updated dependencies in setup.py to use dalf>=0.7.0,<1.0.0
  • Rewrote AutocompleteFilter to extend DALFRelatedFieldAjax
  • Simplified AutocompleteJsonView to use Django's native implementation
  • Added robust error handling for invalid filter parameters (e.g., invalid UUIDs)
  • Updated admin classes to inherit from DALFModelAdmin
  • Modified filter usage from custom classes to tuple format
  • Updated documentation and templates
  • Fixed reverse relation support in autocomplete view

Fixes #582

Checklist

  • [x] I have read the OpenWISP Contributing Guidelines.
  • [x] I have manually tested the changes proposed in this pull request.
  • [x] I have written new test cases for new code and/or updated existing tests for changes to existing code.
  • [x] I have updated the documentation.

Reference to Existing Issue

Closes #582 .

SAMurai-16 avatar Feb 03 '26 19:02 SAMurai-16

[!NOTE]

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • [ ] ▢️ Resume reviews
  • [ ] πŸ” Trigger review
πŸ“ Walkthrough

Walkthrough

Replaces django-admin-autocomplete-filter with django-admin-list-filter (DALF) across code and docs. Updates dependency, tests, templates, JS, templatetags, admin integration, and examples to use DALF APIs and tuple-based list_filter syntax. AutocompleteFilter now subclasses DALFRelatedFieldAjax with an explicit init and persistent init-error handling. AutocompleteJsonView now extends Django’s native AutocompleteJsonView and implements get_queryset to handle reverse relations. Adds OpenwispAdminSite.autocomplete_view to dispatch the configured view. Includes tests, Selenium updates, and a migration adding related_name="books" to Book.shelf.

Sequence Diagram(s)

sequenceDiagram
    participant Browser
    participant DALF_JS as "DALF JS (ow-auto-filter.js)"
    participant DjangoView as "AutocompleteJsonView (server)"
    participant ORM as "Django ORM / DB"

    Browser->>DALF_JS: user types in autocomplete/selects filter
    DALF_JS->>DjangoView: AJAX GET /autocomplete/?q=... & data-field-name
    DjangoView->>ORM: build queryset (handle reverse relations / related_name)
    ORM-->>DjangoView: queryset results
    DjangoView-->>DALF_JS: JSON response (choices)
    DALF_JS-->>Browser: render/update select inputs / hidden fields

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

πŸš₯ Pre-merge checks | βœ… 4
βœ… Passed checks (4 passed)
Check name Status Explanation
Title check βœ… Passed The title clearly and accurately summarizes the main objective of the pull request: migrating from django-admin-autocomplete-filter to dalf, which is the primary change across the codebase.
Description check βœ… Passed The description includes completed checklist items, clear reference to the linked issue (#582), comprehensive summary of changes across multiple files and components, and acknowledges all key aspects of the migration.
Linked Issues check βœ… Passed The pull request successfully addresses all acceptance criteria from issue #582: removes django-admin-autocomplete-filter dependency, achieves feature parity with AutocompleteFilter and AutocompleteJsonView rewrites, maintains Django version compatibility, introduces MIT-licensed dalf, and includes documentation updates.
Out of Scope Changes check βœ… Passed All changes are directly scoped to the autocomplete filter migration. Minor additions like the _js_click helper method and migration file for related_name support are necessary supporting changes for the migration to function properly.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
πŸ§ͺ Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❀️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Feb 03 '26 19:02 coderabbitai[bot]

image

@nemesifier whenever I run openwisp-qa-format it also goes through the env/ folder, which returns errror from the files inside it. Ideally I think this shouldn't happen the format command shall ignore the env/ content .

SAMurai-16 avatar Feb 05 '26 20:02 SAMurai-16

https://github.com/user-attachments/assets/71832429-89ab-4d49-8093-f226a4a624dd

SAMurai-16 avatar Feb 06 '26 19:02 SAMurai-16

[!NOTE] DALF requires Python 3.11+ and Django 4.2+ for full compatibility. Projects using older versions may experience compatibility issues.

SAMurai-16 avatar Feb 06 '26 19:02 SAMurai-16

@nemesifier kindly review

SAMurai-16 avatar Feb 06 '26 19:02 SAMurai-16

image @nemesifier whenever I run `openwisp-qa-format` it also goes through the `env/` folder, which returns errror from the files inside it. Ideally I think this shouldn't happen the format command shall ignore the `env/` content .

put the env in parent dir and then it would be fine

Eeshu-Yadav avatar Mar 07 '26 22:03 Eeshu-Yadav

Hi @SAMurai-16 πŸ‘‹,

This pull request has been marked as stale due to 30 days of inactivity after changes were requested.

As a result, the linked issue(s) have been unassigned from you to allow other contributors to work on it.

However, you can still continue working on this PR! If you push new commits or respond to the review feedback:

  • The issue will be reassigned to you
  • Your contribution is still very welcome

If you need more time or have questions about the requested changes, please let us know. We're happy to help! 🀝

If there's no further activity within 30 more days, this PR will be automatically closed (but can be reopened anytime).

openwisp-companion avatar Mar 09 '26 01:03 openwisp-companion

Test Failures in openwisp-utils

Hello @SAMurai-16 and @nemesifier, (Analysis for commit 85091a5)

There is one test failure:

  • Test Failure: The test_autocomplete_shelf_filter in test_project.tests.test_selenium is failing due to a TimeoutException and NoSuchElementException. This indicates that the Selenium test could not find the element with the CSS selector select[data-field-name="shelf"] + span.select2 .select2-selection within the expected timeout.

Fix: This often happens when the UI element is not present or takes longer to load than anticipated. Consider increasing the timeout in the wait_for_presence call or debugging the test to ensure the element's selector is correct and that the element is indeed rendered before the test attempts to interact with it. If the element's structure or class names have changed, update the selector accordingly.

openwisp-companion avatar Mar 18 '26 11:03 openwisp-companion

Hi @SAMurai-16 πŸ‘‹,

This pull request has been automatically closed due to 89 days of inactivity. After changes were requested, the PR remained inactive.

We understand that life gets busy, and we appreciate your initial contribution! πŸ’™

The door is always open for you to come back:

  • You can reopen this PR at any time if you'd like to continue working on it
  • Feel free to push new commits addressing the requested changes
  • If you reopen the PR, the linked issue will be reassigned to you

If you have any questions or need help, don't hesitate to reach out. We're here to support you!

Thank you for your interest in contributing to OpenWISP! πŸ™

openwisp-companion avatar May 07 '26 01:05 openwisp-companion

Hi @SAMurai-16 πŸ‘‹,

This pull request has been automatically closed due to 90 days of inactivity. After changes were requested, the PR remained inactive.

We understand that life gets busy, and we appreciate your initial contribution! πŸ’™

The door is always open for you to come back:

  • You can reopen this PR at any time if you'd like to continue working on it
  • Feel free to push new commits addressing the requested changes
  • If you reopen the PR, the linked issue will be reassigned to you

If you have any questions or need help, don't hesitate to reach out. We're here to support you!

Thank you for your interest in contributing to OpenWISP! πŸ™

openwisp-companion avatar May 08 '26 01:05 openwisp-companion

Hi @SAMurai-16 πŸ‘‹,

This pull request has been automatically closed due to 91 days of inactivity. After changes were requested, the PR remained inactive.

We understand that life gets busy, and we appreciate your initial contribution! πŸ’™

The door is always open for you to come back:

  • You can reopen this PR at any time if you'd like to continue working on it
  • Feel free to push new commits addressing the requested changes
  • If you reopen the PR, the linked issue will be reassigned to you

If you have any questions or need help, don't hesitate to reach out. We're here to support you!

Thank you for your interest in contributing to OpenWISP! πŸ™

openwisp-companion avatar May 09 '26 01:05 openwisp-companion