Skip to content

fix: handle None on_delete in describe handler - #79

Merged
7tg merged 1 commit into
7tg:mainfrom
foogunlana:fix/describe-on-delete-none
Mar 12, 2026
Merged

fix: handle None on_delete in describe handler#79
7tg merged 1 commit into
7tg:mainfrom
foogunlana:fix/describe-on-delete-none

Conversation

@foogunlana

Copy link
Copy Markdown
Contributor

Summary

  • Fix AttributeError when field.remote_field.on_delete is None (e.g., M2M through relations)
  • Use getattr with a None check instead of hasattr to safely access on_delete

Fixes #78

Changes

In _get_field_metadata (django_admin_mcp/handlers/meta.py):

# Before
if hasattr(field.remote_field, "on_delete"):
    metadata["on_delete"] = field.remote_field.on_delete.__name__

# After
on_delete = getattr(field.remote_field, "on_delete", None)
if on_delete is not None:
    metadata["on_delete"] = on_delete.__name__

Test plan

  • Verify describe handler works for models with M2M through relations
  • Verify describe handler still correctly reports on_delete for ForeignKey fields
  • Verify no regression for models without relationship fields

🤖 Generated with Claude Code

Some fields (e.g. M2M through relations) have remote_field but on_delete
is None, causing AttributeError when accessing .__name__. Use getattr
with a None check instead.
@codecov

codecov Bot commented Mar 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@7tg

7tg commented Mar 12, 2026

Copy link
Copy Markdown
Owner

thank you

@7tg
7tg merged commit 08bba37 into 7tg:main Mar 12, 2026
17 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.

AttributeError in describe handler when field.remote_field.on_delete is None

2 participants