Skip to content

refactor(types): single-source FK detection (mindmap #15, 收敛路线④) - #146

Merged
allmonday merged 1 commit into
masterfrom
refactor/fk-detection-single-source
Sep 4, 2026
Merged

refactor(types): single-source FK detection (mindmap #15, 收敛路线④)#146
allmonday merged 1 commit into
masterfrom
refactor/fk-detection-single-source

Conversation

@allmonday

Copy link
Copy Markdown
Collaborator

Summary

The same three-line "does this field carry a FK marker" check (foreign_key is a str, or a metadata entry carries one) was inlined 7 times across the codebase — the full-project orthogonality review's "pattern 2" (half-done convergence) in its purest form:

# Location Fate
1 er_diagram.py deleted → shared
2 sdl_generator.py deleted → shared (was verbatim-identical)
3 introspection.py deleted → shared (was verbatim-identical)
4 subset.py local def deleted → shared
5 subset.py inline-in-a-loop replaced with one call
6 introspector.py DTO-world variant shell kept (resolving a DTO's source entity is its own concern), the marker check delegates
7 get_fk_fields (the SHARED set API, already used by query_executor & standard_queries) now built on the new single-field detector

Why it matters

Four outlets must agree on "what is an FK" (SDL hides it, ER diagram highlights it, introspection excludes it, DTO projection excludes it) — with 7 copies, any rule change (SQLModel marker evolution, composite FKs) would have to be applied 7 times. The shared function already existed and had two real callers, yet five copies survived beside it.

Changes

  • type_utils.is_fk_field_info(): THE single field-level detector; get_fk_fields builds on it
  • 5 verbatim/inline copies deleted, call sites import the shared detector
  • introspector keeps its shell, delegates the three lines

Verification

  • Behavior is byte-identical (mechanical replacement); existing SDL / ER-diagram / introspection / subset tests all green unchanged
  • New regressions: copy-gone module assertions (any re-inlined copy turns red), detector basics, set-API behavior lock
  • Full suite 1686 passed / 0 failed; ruff check src/ clean

🤖 Generated with Claude Code

The same three-line "does this field carry a FK marker" check was
inlined 7 times: sdl_generator, introspection, er_diagram (three
verbatim-identical copies), subset (a local def + an inline copy in a
loop), the introspector DTO-world variant, and inside get_fk_fields —
which is the SHARED API two callers already use. Textbook half-done
convergence (pattern 2): the shared function existed, yet five copies
survived beside it.

- type_utils.is_fk_field_info(): the single field-level detector;
  get_fk_fields builds on it
- the four verbatim copies and the subset inline copy are deleted;
  call sites import the shared detector
- the introspector variant keeps its shell (resolving a DTO's source
  entity is DTO-world-specific) but delegates the marker check

Behavior is byte-identical (mechanical replacement); regression tests
lock the single source (module-level copy-gone assertions + detector
basics + set-API behavior).

Co-Authored-By: Claude <noreply@anthropic.com>
@allmonday
allmonday merged commit c1b2a72 into master Sep 4, 2026
5 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.

1 participant