refactor(types): single-source FK detection (mindmap #15, 收敛路线④) - #146
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The same three-line "does this field carry a FK marker" check (
foreign_keyis 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:er_diagram.pysdl_generator.pyintrospection.pysubset.pylocal defsubset.pyinline-in-a-loopintrospector.pyDTO-world variantget_fk_fields(the SHARED set API, already used by query_executor & standard_queries)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_fieldsbuilds on itVerification
ruff check src/clean🤖 Generated with Claude Code