Skip to content

Move template-field checks out of __init__ in Hive sensors#70334

Merged
shahar1 merged 3 commits into
apache:mainfrom
1fanwang:fix-hive-sensors-init
Jul 24, 2026
Merged

Move template-field checks out of __init__ in Hive sensors#70334
shahar1 merged 3 commits into
apache:mainfrom
1fanwang:fix-hive-sensors-init

Conversation

@1fanwang

@1fanwang 1fanwang commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

table/partition (HivePartitionSensor) and partition_names (NamedHivePartitionSensor) are template fields, so they are rendered after __init__ runs. Two constructors read them:

  • HivePartitionSensor defaulted partition with if not partition: partition = "ds='{{ ds }}'" — an imperative read of the field. Switched to the sanctioned partition or "ds='{{ ds }}'" idiom (behaviour identical).
  • NamedHivePartitionSensor raised TypeError in __init__ when partition_names was a str. A whole-list native template (partition_names="{{ params.names }}") is a str before rendering, so the constructor rejected it outright. Moved the array-type check to poke(), which runs after rendering.

related: #70296

Testing Done

validate_operators_init.py exits 0 for both sensors after the change (RED before, flagging if not partition: and if isinstance(partition_names, str):).

New test_native_templated_partition_names drives the render→poke path with a native-templated list; it fails on the pre-fix source (TypeError at construction) and passes after. test_named_hive_partition.py: 6 passed, 4 skipped (need a live metastore). HivePartitionSensor's change is a behaviour-preserving refactor, covered by the existing suite.


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: GitHub Copilot CLI following the guidelines

@1fanwang
1fanwang marked this pull request as draft July 24, 2026 05:47
@1fanwang
1fanwang marked this pull request as ready for review July 24, 2026 06:23
@shahar1 shahar1 removed the backport-to-v3-3-test Backport to v3-3-test label Jul 24, 2026
1fanwang added 3 commits July 24, 2026 11:17
table/partition (HivePartitionSensor) and partition_names (NamedHivePartitionSensor)
are template fields, rendered after __init__ runs. HivePartitionSensor used an
imperative default (if not partition: partition = ...) reading the field;
NamedHivePartitionSensor raised TypeError in the constructor when partition_names
was a str, which rejected a whole-list native template (a str before rendering).

Use the sanctioned 'partition or default' idiom, and move the array-type check to
poke(), which runs after rendering.

related: apache#70296
Signed-off-by: 1fanwang <1fannnw@gmail.com>
Signed-off-by: 1fanwang <1fannnw@gmail.com>
Signed-off-by: 1fanwang <1fannnw@gmail.com>
@1fanwang
1fanwang force-pushed the fix-hive-sensors-init branch from ab4caa9 to d5b77fa Compare July 24, 2026 18:20
@shahar1
shahar1 merged commit 39381cc into apache:main Jul 24, 2026
83 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants