Fix nested field access in message template formatting#175
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🔗 Linked repositories identifiedCodeRabbit considers these linked repositories for cross-repo context during reviews:
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughMessage template formatting now resolves dotted fields by traversing nested attribute values, while literal dotted keys retain precedence. Field access uses own-property checks to exclude prototype members. Unsupported or unresolved paths fall back to the raw template with warnings. Tests cover nested and deep fields, precedence, debug formatting, missing values, bracket syntax, and prototype-member protection. A patch changeset documents the updated behavior. 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/logfire-api/src/formatter.ts`:
- Around line 59-64: Reject unsupported bracket syntax in the formatter before
literal-key lookup: update the field-resolution logic around Object.hasOwn in
packages/logfire-api/src/formatter.ts lines 59-64 to throw KnownFormattingError
whenever fieldName contains [ or ]. Add a regression test in
packages/logfire-api/src/formatter.test.ts line 10 using a record with an own
"a[0]" key, asserting the raw template is returned and the warning matches
exactly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 0fff08e8-db78-410d-ad3f-1e9ac7f29f23
📒 Files selected for processing (3)
.changeset/nested-template-fields.mdpackages/logfire-api/src/formatter.test.tspackages/logfire-api/src/formatter.ts
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
pydantic/logfire(manual)pydantic/pydantic-ai(manual)
petyosi
left a comment
There was a problem hiding this comment.
Please add paired regressions for the bracket behavior documented in the changeset: {a[0]} with no matching literal key should warn and return the raw template, while {a[0]} with an own 'a[0]' key should render that value. The latter preserves existing main behavior and literal-key precedence, so we should test it rather than reject bracket characters before lookup.
|
added both in 4ba94d4: |
|
since you're doing a review pass (thanks for the #172 approval!): this one is fully addressed too. the paired bracket regressions you asked for landed in 4ba94d4, coderabbit approved after the changeset clarification, and there are no open threads left. ready whenever you are. same honest workflow as the rest: built with Claude Code's help, final diff read by me. |
Fixes #174.
getFieldinpackages/logfire-api/src/formatter.tsresolved every dotted path segment against the top-level attribute record, so{user.name}fell back to the raw template and{a.b}could silently render an unrelated top-levelb. Nested paths now walk into the attribute value, and a literal dotted key likehttp.methodstill wins over traversal so flat OTel-style attribute names keep their behavior.Both follow-ups from the issue are in: field lookups use
Object.hasOwnat the top level and during traversal, so prototype members like{user.toString}no longer resolve (regression tests included), and the changeset now mentions the bracket-syntax change ({a[0]}used to render the stringundefined, now it warns and falls back to the raw template).New
formatter.test.tscovers nested resolution, precedence, debug=syntax, missing-field fallbacks, and the prototype cases; changeset is a patch forlogfire. Ranpnpm run checkfrom the root, all green on Node 24.quick note: built with Claude Code's help, and I went through the final diff myself. freshman in college doing my best here, so if anything looks off I'd honestly love to know why :)