Skip to content

fix: handle None on_delete in describe handler#79

Open
foogunlana wants to merge 1 commit into7tg:mainfrom
foogunlana:fix/describe-on-delete-none
Open

fix: handle None on_delete in describe handler#79
foogunlana wants to merge 1 commit into7tg:mainfrom
foogunlana:fix/describe-on-delete-none

Conversation

@foogunlana
Copy link

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.
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

1 participant