Skip to content

Commit

Permalink
Use 0 and 1 instead of bools
Browse files Browse the repository at this point in the history
  • Loading branch information
iambriccardo committed Oct 3, 2023
1 parent df9c8b3 commit eeb0c9a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/sentry/api/endpoints/project_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ def put(self, request: Request, project) -> Response:
if "filters:chunk-load-error" in options:
project.update_option(
"filters:chunk-load-error",
bool(options["filters:chunk-load-error"]),
"1" if bool(options["filters:chunk-load-error"]) else "0",
)
if "filters:blacklisted_ips" in options:
project.update_option(
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/api/serializers/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def format_options(attrs: dict[str, Any]) -> dict[str, Any]:
"sentry:reprocessing_active": bool(options.get("sentry:reprocessing_active", False)),
"filters:blacklisted_ips": "\n".join(options.get("sentry:blacklisted_ips", [])),
"filters:react-hydration-errors": bool(options.get("filters:react-hydration-errors", True)),
"filters:chunk-load-error": bool(options.get("filters:chunk-load-error", True)),
"filters:chunk-load-error": options.get("filters:chunk-load-error", "1") == "1",
f"filters:{FilterTypes.RELEASES}": "\n".join(
options.get(f"sentry:{FilterTypes.RELEASES}", [])
),
Expand Down
8 changes: 5 additions & 3 deletions src/sentry/relay/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ def get_filter_settings(project: Project) -> Mapping[str, Any]:

error_messages += project.get_option(f"sentry:{FilterTypes.ERROR_MESSAGES}") or []

# TODO: refactor the system to allow management of error messages filtering via the inbound filters, since right
# now the system maps an option to a single top-level filter like "ignoreTransactions".
enable_react = project.get_option("filters:react-hydration-errors")
if enable_react:
# 418 - Hydration failed because the initial UI does not match what was rendered on the server.
Expand All @@ -146,9 +148,9 @@ def get_filter_settings(project: Project) -> Mapping[str, Any]:
"*https://reactjs.org/docs/error-decoder.html?invariant={418,419,422,423,425}*"
]

enable_chunk_upload_error_filter = project.get_option("filters:chunk-load-error")
if enable_chunk_upload_error_filter:
# ChunkLoadError: Loading chunk 3662 failed.\n(error: https://xxx.com/_next/static/chunks/29107295-0151559bd23117ba.js)
if project.get_option("filters:chunk-load-error") == "1":
# ChunkLoadError: Loading chunk 3662 failed.\n(error:
# https://xxx.com/_next/static/chunks/29107295-0151559bd23117ba.js)
error_messages += ["ChunkLoadError: Loading chunk * failed.\n(error: *)"]

if error_messages:
Expand Down
12 changes: 8 additions & 4 deletions tests/sentry/api/endpoints/test_project_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,11 +858,15 @@ def test_react_hydration_errors(self):
assert resp.data["options"]["filters:react-hydration-errors"] == value

def test_chunk_load_error(self):
value = False
options = {"filters:chunk-load-error": value}
options = {"filters:chunk-load-error": False}
resp = self.get_success_response(self.org_slug, self.proj_slug, options=options)
assert self.project.get_option("filters:chunk-load-error") == "0"
assert resp.data["options"]["filters:chunk-load-error"] is False

options = {"filters:chunk-load-error": True}
resp = self.get_success_response(self.org_slug, self.proj_slug, options=options)
assert self.project.get_option("filters:chunk-load-error") == value
assert resp.data["options"]["filters:chunk-load-error"] == value
assert self.project.get_option("filters:chunk-load-error") == "1"
assert resp.data["options"]["filters:chunk-load-error"] is True

def test_relay_pii_config(self):
value = '{"applications": {"freeform": []}}'
Expand Down
10 changes: 5 additions & 5 deletions tests/sentry/relay/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def test_project_config_uses_filter_features(
default_project.update_option("sentry:error_messages", error_messages)
default_project.update_option("sentry:releases", releases)
default_project.update_option("filters:react-hydration-errors", False)
default_project.update_option("filters:chunk-load-error", False)
default_project.update_option("filters:chunk-load-error", "0")

if has_blacklisted_ips:
default_project.update_option("sentry:blacklisted_ips", blacklisted_ips)
Expand Down Expand Up @@ -209,18 +209,18 @@ def test_project_config_uses_filter_features(
@django_db_all
@region_silo_test(stable=True)
def test_project_config_with_chunk_load_error_filter(default_project):
# The react-hydration-errors option is set as string in the defaults but then its changed as a boolean in the
# options endpoint, which is something that should be changed.
default_project.update_option("filters:react-hydration-errors", False)
default_project.update_option("filters:chunk-load-error", True)
default_project.update_option("filters:chunk-load-error", "1")

project_cfg = get_project_config(default_project, full_config=True)

cfg = project_cfg.to_dict()
_validate_project_config(cfg["config"])
cfg_error_messages = get_path(cfg, "config", "filterSettings", "errorMessages")

assert cfg_error_messages == {
"patterns": ["ChunkLoadError: Loading chunk * failed.\n(error: *)"]
}
assert len(cfg_error_messages) == 1


@django_db_all
Expand Down

0 comments on commit eeb0c9a

Please sign in to comment.