ColtenOuO opened a new pull request, #70508:
URL: https://github.com/apache/airflow/pull/70508

   > [!NOTE]
   > Blocked on #70505. The `validate-operators-init` hook on `main` still flags
   > `is None` provision checks in `__init__`, so CI will be red until that 
merges.
   > Kept as a draft until then — verified clean against the checker from #70505
   > (exit 0, no exemption entry needed).
   
   Moves the two argument-provision checks of `Neo4jOperator` back to 
`__init__`, one of the reverts tracked in #70503.
   
   Whether `cypher` or `sql` was passed is a property of how the Dag was 
written, not of the rendered value. `execute()` cannot answer it: with 
`render_template_as_native_obj=True` a supplied field can render to `None`, so 
the check there reports an argument the author did provide as missing. Checking 
at construction also turns a static authoring mistake into a Dag import error 
rather than a failure on every task instance.
   
   **Both** provision checks move, not only `cypher is None`. After #70373 the 
operator keeps `sql` and `cypher` as separate fields, so 
`Neo4jOperator(sql=...)` is valid with `cypher` unset — the constructor check 
has to be `cypher is None and sql is None`. Once it is written that way, 
leaving the mutual-exclusivity check in `execute()` would split two checks that 
ask the same question across two phases.
   
   The `execute()` guard is kept deliberately: `Neo4jHook.run` takes a `str`, 
and the constructor check does not narrow `self.cypher` to `str` (it is 
legitimately `None` when `sql` was used). A passed field can also render to 
`None`, which is exactly the case the guard covers. `cast` would hide that and 
`assert` is not allowed in production code.
   
   <details><summary>Testing done</summary>
   
   - `providers/neo4j/tests/unit/neo4j/operators/test_neo4j.py`: 6 passed. The 
two
     reverted tests assert construction-time failure again; a new test covers 
the
     `execute()` guard by rendering a supplied field to `None`.
   - Checker from #70505 on the operator: exit 0 — no exemption entry needs 
re-adding.
   - Checker on `main`: exit 1, as expected before #70505 merges.
   - `breeze run mypy` on the operator: clean.
   
   </details>
   
   related: #70503, #70505
   
   ---


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to