Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ def redact_password(cls, v: str | None, field_info: ValidationInfo) -> str | Non
@field_validator("extra", mode="before")
@classmethod
def redact_extra(cls, v: str | None) -> str | None:
if v is None:
return None
if v is None or v == "":
return v
try:
extra_dict = json.loads(v)
redacted_dict = redact(extra_dict)
return json.dumps(redacted_dict)
except json.JSONDecodeError:
# Do not return un-redacted extra because this could cause sensitive information to be exposed.
# This code path should never been hit as ``Connection._validate_extra`` sure that ``extra`` is
# always a valid JSON string. We add this safeguard just in case and to make the coupling
# This code path should never be hit as ``Connection._validate_extra`` makes sure that ``extra`` is
# always a valid JSON string (if truthy). We add this safeguard just in case and to make the coupling
# explicit.
raise ValueError(
"This code path should never happen as persisted Connections (DB layer) should always enforce `extra` as a JSON string."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,19 @@ def test_get_should_respond_200_with_extra(self, test_client, session):
assert body["conn_type"] == TEST_CONN_TYPE
assert body["extra"] == '{"extra_key": "extra_value"}'

@pytest.mark.parametrize("extra_value", [None, ""])
def test_get_should_respond_200_with_empty_extra(self, test_client, session, extra_value):
"""Empty string or NULL extra should not break serialization (regression test for #64950)."""
self.create_connection()
connection = session.scalars(select(Connection)).first()
connection.extra = extra_value
session.commit()
response = test_client.get(f"/connections/{TEST_CONN_ID}")
assert response.status_code == 200
body = response.json()
assert body["connection_id"] == TEST_CONN_ID
assert body["extra"] == extra_value

@pytest.mark.enable_redact
def test_get_should_respond_200_with_extra_redacted(self, test_client, session):
self.create_connection()
Expand Down
Loading