Skip to content

Fix admin search for Address and Contact company foreign keys - #12440

Merged
SchrodingersGat merged 1 commit into
inventree:masterfrom
bhumin18:fix-admin-search-foreignkey
Jul 22, 2026
Merged

Fix admin search for Address and Contact company foreign keys#12440
SchrodingersGat merged 1 commit into
inventree:masterfrom
bhumin18:fix-admin-search-foreignkey

Conversation

@bhumin18

Copy link
Copy Markdown
Contributor

Summary

Fix a Django admin search error for the Address and Contact models.

Problem

Searching in the Address or Contact admin pages raises the following error because search_fields includes the company ForeignKey directly:

FieldError: Unsupported lookup 'icontains' for ForeignKey or join on the field not permitted.

Django attempts to apply the icontains lookup to the ForeignKey, which is not supported.

Fix

Update the admin search configuration to search using the related company's name by replacing:

  • companycompany__name

in both AddressAdmin and ContactAdmin.

Testing

  • Reproduced the error by searching in the Django admin.
  • Applied the fix.
  • Verified that searching no longer raises the exception.

@netlify

netlify Bot commented Jul 21, 2026

Copy link
Copy Markdown

Deploy Preview for inventree-web-pui-preview canceled.

Name Link
🔨 Latest commit 440119b
🔍 Latest deploy log https://app.netlify.com/projects/inventree-web-pui-preview/deploys/6a5f41e1be76c000089c2728

@SchrodingersGat SchrodingersGat added bug Identifies a bug which needs to be addressed backport Apply this label to a PR to enable auto-backport action backport-to-1.4.x labels Jul 21, 2026
@SchrodingersGat SchrodingersGat added this to the 1.5.0 milestone Jul 21, 2026
@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.87%. Comparing base (b723f5d) to head (440119b).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #12440   +/-   ##
=======================================
  Coverage   86.87%   86.87%           
=======================================
  Files        1442     1442           
  Lines       94942    94942           
  Branches    11101    11101           
=======================================
  Hits        82482    82482           
  Misses      12395    12395           
  Partials       65       65           
Flag Coverage Δ
backend 91.06% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Backend Apps 92.57% <100.00%> (ø)
Backend General 93.49% <ø> (ø)
Frontend 79.66% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@SchrodingersGat
SchrodingersGat merged commit 8d8ecf2 into inventree:master Jul 22, 2026
45 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

💚 All backports created successfully

Status Branch Result
1.4.x

Questions ?

Please refer to the Backport tool documentation and see the Github Action logs for details

SchrodingersGat pushed a commit that referenced this pull request Jul 23, 2026
(cherry picked from commit 8d8ecf2)

Co-authored-by: Bhumin Paladiya <139330832+bhumin18@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport Apply this label to a PR to enable auto-backport action backport-to-1.4.x bug Identifies a bug which needs to be addressed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants