Skip to content

fix(er): keep same-name models apart in Mermaid (#223) - #234

Merged
FROWNINGdev merged 2 commits into
FROWNINGdev:mainfrom
sarankumar1325:fix/mermaid-same-name-models
Nov 10, 2026
Merged

FROWNINGdev merged 2 commits into
FROWNINGdev:mainfrom
sarankumar1325:fix/mermaid-same-name-models

Conversation

@sarankumar1325

Copy link
Copy Markdown
Contributor

Summary

Mermaid has a single namespace for entity names, so basket.Line and order.Line became one Line box with both apps' columns, linked to both parents. _build_mermaid() now writes a class name that more than one app defines as <app>_<Model> (basket_Line, order_Line). The other names stay bare, so diagrams of projects without duplicate names are byte-identical to before.

Relation ends use the same ids. A bare target such as ForeignKey(Line, ...) resolves to the Line in the field's own app. An app-qualified reference ('order.Line') keeps its app. Anything else falls back to the first one found. 'self' points at the model's own entity.

I left out the optional alias label (basket_Line["basket.Line"]) to keep the change small. I'm happy to add it if you want it.

Type of change

  • Bug fix (non-breaking, restores expected behaviour)
  • Feature (non-breaking, adds a capability)
  • Breaking change (existing users have to update config or code)
  • Docs / README / comments only (no runtime effect)
  • Internal refactor (no behaviour change, no public API change)
  • Dependency bump
  • CI / build / tooling

Test plan

New MermaidSameNameModelsTest in cli/tests/test_er_formats.py:

  • test_colliding_names_get_their_app_prefix: the repro from the issue. Two separate basket_Line / order_Line entities, each with only its own columns, and each FK edge starts from its own Line. Fails on main.
  • test_edges_to_a_colliding_name_pick_the_right_app: covers same-app resolution, 'self', and 'order.Line' from a third app. Fails on main.
  • test_unique_names_are_unchanged: the entity list for the golden/saleor fixture is exactly the bare model names.

I also ran _build_mermaid over every fixture directory before and after the change. Each project's output is identical. Only the combined fixtures/golden scan changed, because cms.Page and wagtail.Page collide there.

cd cli && python -m pytest -q        # 1115 passed, 6 skipped
python -m ruff check orm_lens tests ../compat/django-orm-lens/django_orm_lens ../compat/django-orm-lens/django_orm_lens_cli.py
python -m mypy orm_lens ../compat/django-orm-lens/django_orm_lens ../compat/django-orm-lens/django_orm_lens_cli.py

Checklist

  • I ran the full test suite locally (cd cli && pytest -q for Python, npm test for TypeScript) and it is green
  • I added or updated tests that cover the change (bugfixes should get a regression test)
  • If the change is user-facing I updated the CHANGELOG under ## [Unreleased]
  • If the change touches the MCP tool contract (new tool, new arg, new error code) I updated the tool description in mcp_server.py and the relevant tests in test_mcp_server.py
  • If this is a breaking change I called it out under ## Summary above and suggested a migration path

Related issues / discussions

Closes #223

I wrote this with help from an AI coding assistant, and I reviewed and tested the change myself.

A class name defined in more than one app is written as <app>_<Model>, and relation ends resolve to the model in the field's own app or the app named in the reference. Diagrams without duplicate names are unchanged.
@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@FROWNINGdev

Copy link
Copy Markdown
Owner

Thanks @sarankumar1325. Prefixing only colliding names keeps every other diagram byte-identical, which is what I wanted. Merged.

@FROWNINGdev
FROWNINGdev merged commit 0ffaa00 into FROWNINGdev:main Nov 10, 2026
19 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.

Mermaid ER merges two models that share a class name (basket.Line + order.Line → one box)

2 participants