feat(nimbus): add validation to nimbus review serializer for targeting context fields within version range#15406
Conversation
…g context fields within version range
jaredlockhart
left a comment
There was a problem hiding this comment.
This is so so so sick I'm so pleased with this. Very well written, very clear, very idiomatic with the project patterns, very clearly and well tested.
Try to do the test fixture file approach. If it's a nightmare then we can fall back to mocking but it's worth at least trying to set it up now.
Great job @moibra05 🙏 🎉
| extracted_root_fields = set() | ||
| for subexpr in collect_exprs(targeting_config.targeting): | ||
| try: | ||
| json.loads(subexpr) | ||
| continue | ||
| except json.JSONDecodeError: | ||
| if subexpr.startswith("."): | ||
| continue | ||
| extracted_root_fields.add(subexpr.partition(".")[0]) |
There was a problem hiding this comment.
Oh then we should pull this out into a utility somewhere since we're also doing it here:
| ) | ||
| ) | ||
|
|
||
| unknown_fields = extracted_root_fields - fields |
There was a problem hiding this comment.
Set logic is the greatest thing ever 💯 💯 💯
| patch( | ||
| "experimenter.experiments.api.v5.serializers.collect_exprs", | ||
| return_value=["knownField", "unknownField", ".id"], | ||
| ), | ||
| patch( | ||
| "experimenter.experiments.api.v5.serializers.TargetingContextFields.for_application", | ||
| return_value={"knownField"}, |
There was a problem hiding this comment.
I'm not sure mocking out the function calls here is the right way to do this. Usually we follow a pattern of having test fixture data and pointing the loader at it and forcing it to reload and then letting all the logic flow naturally. I'd say see if you can do that rather than mocking it out at the function level.
| fields_by_version = { | ||
| "v120.0.0": {"knownField"}, | ||
| "v121.0.0": {"knownField", "anotherKnownField"}, | ||
| "v122.0.0": {"knownField", "anotherKnownField", "thirdKnownField"}, | ||
| "v123.0.0": {"knownField"}, | ||
| } |
There was a problem hiding this comment.
Yeah exactly like we could put these in fixture files and have the loader pick them by mocking out the file path.
| "experimenter.experiments.api.v5.serializers.collect_exprs", | ||
| return_value=["knownField"], |
There was a problem hiding this comment.
And then we should be able to setup some dummy test targeting configs.
Because
This commit
Fixes #14925