-
Notifications
You must be signed in to change notification settings - Fork 2
fix: interceptor from parent not inherit to child module #329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Summary by CodeRabbit
WalkthroughA nil-check was added in DynamicModule.New to default a sub-module’s interceptor to its parent’s interceptor when the new module’s interceptor is unset. No other logic or public signatures changed. Changes
Sequence Diagram(s)sequenceDiagram
actor Caller
participant Parent as Parent Module
participant Factory as DynamicModule.New
participant Child as New Sub-Module
Caller->>Parent: Create sub-module
Parent->>Factory: New()
Note over Factory: Assemble DataProviders & Middlewares
alt Interceptor not provided
Factory->>Factory: if newMod.interceptor == nil
Factory->>Child: set interceptor = Parent.interceptor
Note right of Child: Inherits parent's interceptor (changed behavior)
else Interceptor provided
Factory->>Child: keep provided interceptor
end
Factory-->>Caller: return Child
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).Please share your feedback with us on this Discord post. 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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
core/module.go(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Analyze (go)
| if newMod.interceptor == nil { | ||
| newMod.interceptor = m.interceptor | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Interceptor inheritance is applied too early and gets overwritten by initModule.
initModule unconditionally assigns module.interceptor = opt.Interceptor (Line 137). Your pre-init nil-check sets newMod.interceptor, but it’s then clobbered when opt.Interceptor is nil. Do the fallback on opt before calling initModule, or guard the assignment inside initModule.
Apply this diff in New():
newMod := &DynamicModule{isRoot: false}
newMod.DataProviders = append(newMod.DataProviders, m.GetExports()...)
newMod.Middlewares = append(newMod.Middlewares, m.Middlewares...)
- if newMod.interceptor == nil {
- newMod.interceptor = m.interceptor
- }
+ // Inherit parent interceptor only when none provided
+ if opt.Interceptor == nil {
+ opt.Interceptor = m.interceptor
+ }
initModule(newMod, opt)
return newModAlternatively (if you prefer keeping the current call site unchanged), guard the interceptor set in initModule:
- module.interceptor = opt.Interceptor
+ if opt.Interceptor != nil {
+ module.interceptor = opt.Interceptor
+ }Run to confirm no other writes override the interceptor unexpectedly:
🏁 Script executed:
#!/bin/bash
# List all assignments to .interceptor to ensure no later overwrite
rg -n --type=go -C2 '\.interceptor\s*='Length of output: 1298
Fix interceptor inheritance being clobbered by initModule
initModule unconditionally sets module.interceptor = opt.Interceptor (core/module.go:137), which overwrites the fallback done earlier in New() (core/module.go:104–106). Either apply the fallback to opt before calling initModule or guard the assignment in initModule.
Apply this diff in New():
newMod := &DynamicModule{isRoot: false}
newMod.DataProviders = append(newMod.DataProviders, m.GetExports()...)
newMod.Middlewares = append(newMod.Middlewares, m.Middlewares...)
- if newMod.interceptor == nil {
- newMod.interceptor = m.interceptor
- }
+ // Inherit parent interceptor only when none provided
+ if opt.Interceptor == nil {
+ opt.Interceptor = m.interceptor
+ }
initModule(newMod, opt)
return newModOr guard inside initModule:
- module.interceptor = opt.Interceptor
+ if opt.Interceptor != nil {
+ module.interceptor = opt.Interceptor
+ }core/module.go:104–106,137.
🤖 Prompt for AI Agents
core/module.go lines 104-106 and 137: New() sets a fallback interceptor on
newMod (lines 104–106) but initModule unconditionally assigns module.interceptor
= opt.Interceptor at line 137, clobbering the fallback; either copy the fallback
into opt.Interceptor before calling initModule so initModule uses the
already-resolved interceptor, or change initModule to only assign
module.interceptor = opt.Interceptor if opt.Interceptor != nil (i.e., guard the
assignment) so the fallback set in New() isn't overwritten.
No description provided.