fix(generic): honor m tags during realization - #3505
Conversation
|
默认的tag是mapstructure是吧 用自定义的m对开发者的心智负担有点重 |
|
统一成 mapstructure |
There was a problem hiding this comment.
Pull request overview
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Updates the generic map realization flow to respect m struct tags when decoding, adding a regression test for the m-tag round trip (fix for #3503).
Changes:
- Configure
mapstructuredecoding inRealizeto useTagName: "m". - Add a test struct with an
m:"user_id"tag and a round-trip test coveringGeneralize+Realize.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| filter/generic/generalizer/map.go | Switches Realize to a configured mapstructure decoder that honors m tags. |
| filter/generic/generalizer/map_test.go | Adds a regression test ensuring m tags survive generalize/realize round trips. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| generalized, err := mockMapGeneralizer.Generalize(original) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, "42", generalized.(map[string]any)["user_id"]) |
| decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{ | ||
| Result: newobj, | ||
| TagName: "m", | ||
| }) | ||
| if err != nil { | ||
| return nil, perrors.Errorf("realizing map failed, %v", err) | ||
| } |
|
虽然我 A 了,但是 copilot 的两个 comment 我觉得很有道理,处理完再 merge。 |
@Oxidaner what about these |
8bbc5ba to
27dcf7e
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #3505 +/- ##
===========================================
+ Coverage 46.76% 55.30% +8.53%
===========================================
Files 295 475 +180
Lines 17172 36822 +19650
===========================================
+ Hits 8031 20364 +12333
- Misses 8287 14833 +6546
- Partials 854 1625 +771 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{ | ||
| Result: newobj, | ||
| TagName: "mapstructure", | ||
| }) |
|
update to latest develop branch to fix the ci fail |
27dcf7e to
6943581
Compare
| // setInMap sets the struct into the map using the tag or the name of the struct as the key | ||
| func setInMap(m map[string]any, structField reflect.StructField, value any) (result map[string]any) { | ||
| result = m | ||
| if tagName := structField.Tag.Get("m"); tagName == "" { |
There was a problem hiding this comment.
我发现这里m还不能改为mapstructure 会影响下游用户 还是改回来吧 不好意思😂
6943581 to
9d33cf7
Compare
|



Description
Fixes #3503 (issue)
Checklist
develop