Skip to content

Change coerce_type default to True for JsonData/EntityJson#4

Merged
cmttt merged 1 commit intomainfrom
ls/coerce-type-default-true
Mar 26, 2026
Merged

Change coerce_type default to True for JsonData/EntityJson#4
cmttt merged 1 commit intomainfrom
ls/coerce-type-default-true

Conversation

@cmttt
Copy link
Copy Markdown
Owner

@cmttt cmttt commented Mar 26, 2026

Summary

Change coerce_type default from False to True in JsonData (and by inheritance, EntityJson).

Why

JSON payloads are inherently loosely typed — BigIntegers become strings (bigint_as_string=True), booleans appear where strings are expected, etc. Requiring exact type matches by default causes InvalidJsonType errors that silently disable rules.

With coerce_type=True by default, the engine attempts int("123"), str(False), etc. If coercion fails (e.g., int("hello")), InvalidJsonType is still raised — so genuinely wrong types are still caught.

This eliminates an entire class of rule-authoring footguns. Rule authors no longer need to remember coerce_type=True for every snowflake ID, every field that might be a bool vs string, etc.

Risk

Low. Coercion only applies when the value exists but has the wrong type. If coercion succeeds, the rule gets the right value. If coercion fails, the same InvalidJsonType error fires. No behavior change for rules where types already match.

Test plan

  • Existing test_execute_coerce_type tests still pass
  • Deploy and verify InvalidJsonType Sentry events decrease

JSON payloads are inherently loosely typed — BigIntegers become strings,
booleans appear where strings are expected, etc. Requiring exact type
matches by default causes InvalidJsonType errors that silently disable
rules (11.6M+ Sentry events).

With coerce_type=True by default, the engine attempts to convert the
value to the declared type (e.g., int("123") or str(False)). If
coercion fails, InvalidJsonType is still raised.

This affects both JsonData and EntityJson (EntityJsonArguments inherits
from json_data.Arguments).
@cmttt cmttt merged commit cd99ce2 into main Mar 26, 2026
@cmttt cmttt mentioned this pull request Apr 1, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant