Skip to content

Preserve unknown enum values instead of silently dropping them#1485

Open
phongl7 wants to merge 1 commit into
databricks:mainfrom
phongl7:phongly/fix_missing_warehouse_type
Open

Preserve unknown enum values instead of silently dropping them#1485
phongl7 wants to merge 1 commit into
databricks:mainfrom
phongl7:phongly/fix_missing_warehouse_type

Conversation

@phongl7

@phongl7 phongl7 commented Jun 25, 2026

Copy link
Copy Markdown

What

When the server returns an enum value this SDK version doesn't recognize, the SDK
currently coerces it to None (_enum) or skips it (_repeated_enum). Combined with
as_dict() omitting None fields, this means the value disappears entirely — silent
data loss.

This PR preserves unknown enum values via a small UnknownEnumValue wrapper that
exposes .value, so the data round-trips through as_dict() while staying clearly
distinguishable from a known enum member.

Why

Generated enums come from a versioned OpenAPI spec and can lag behind the service. A
concrete case: warehouses.list() returns the real-time warehouse type REAL_TIME,
which isn't in EndpointInfoWarehouseType, so warehouse_type is dropped from
as_dict() output entirely.

Fixes #1484

Behavior change

# before
_enum({"warehouse_type": "REAL_TIME"}, "warehouse_type", EndpointInfoWarehouseType)
# -> None  (field then dropped from as_dict())

# after
# -> UnknownEnumValue('REAL_TIME')  (as_dict() emits "warehouse_type": "REAL_TIME")

Known values still resolve to the proper enum member; absent/empty fields still return
None. This is a behavior change for callers that relied on unknown values becoming
None — flagging for maintainer input (see #1484 for the discussion).

Scope

This addresses the general silent-drop (problem 2 in #1484). The missing REAL_TIME
enum value itself (problem 1) lives in the upstream OpenAPI spec and isn't fixable in
this repo's generated sql.py.

Tests

Updated tests/test_internal.py to cover preservation + .value round-trip for both
_enum and _repeated_enum; added a case asserting absent fields still return None.
tests/test_internal.py and tests/generated/ pass; ruff format/ruff check clean.

When the server returns an enum value this SDK version doesn't recognize,
_enum coerced it to None and _repeated_enum skipped it. Combined with
as_dict() omitting None fields, the value disappeared entirely (silent data
loss). For example, warehouses.list() drops warehouse_type for the REAL_TIME
warehouse type, which isn't in EndpointInfoWarehouseType.

Preserve unknown values via an UnknownEnumValue wrapper that exposes .value so
the data round-trips through as_dict(), while staying distinguishable from a
known enum member. Known values and absent/empty fields are unchanged.
@github-actions

Copy link
Copy Markdown

If integration tests don't run automatically, an authorized user can run them manually by following the instructions below:

Trigger:
go/deco-tests-run/sdk-py

Inputs:

  • PR number: 1485
  • Commit SHA: bad3f1227e92fc361f24c96afcb5d4a848e372c2

Checks will be approved automatically on success.

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.

[ISSUE] warehouses.list() silently drops warehouse_type for warehouse types not in the SDK enum

1 participant