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

   This is a bug that came out of the Airflow Summit workshop, with a couple of 
small related changes along for the ride.
   
   
   Bug: when a user has two custom DeadlineReferences with the same class name, 
the one which happened to be parsed first got silently overwritten by the 
second.  Worse than losing the shorthand, the surviving instance serializes 
under its own qualname, so the scheduler evaluates the wrong one.  Nothing was 
logged above INFO, and the message that was emitted was not helpful since it 
only included __name__, which is identical between the two conflicting 
references.
   
   With this change neither one gets a claim on the 
`DeadlineReference.MyReference` shorthand, a warning is logged which names both 
classes by qualname, and both remain fully usable by importing and 
instantiating the class directly.  I decided to withhold the shorthand notation 
from both rather than awarding it to the first since, before this change, a Dag 
written using the short name would mysteriously start using whichever reference 
happened to parse first after each restart, based on the arbitrary import order.
    
   Two smaller behaviour changes are included as off-shoots.  A custom 
reference whose name collides with something already on `DeadlineReference`, 
such as `DAGRUN_QUEUED_AT` or `TYPES`, now raises rather than replacing it, 
since unbinding a built-in would break every Dag using it.  And registering a 
reference now replaces its `DeadlineReference.TYPES` entry instead of appending 
another.  This means that re-registering an edited class is now self-cleaning 
and self-updating; it no longer leaves duplicates behind.  Both comparisons are 
based off the module-qualified name because a re-parse produces a new class 
object for the same reference and `__name__` alone cannot tell two modules 
apart.
   
   While I was in there, I renamed `register_custom_reference`, which predates 
Jarek's PR (#66737) which enforces registration as a plugin.  The naming was 
awkward and slightly misleading to begin with, and became outright confusing 
once users were unsure what exactly they were registering (registering a plugin 
vs registering the reference shorthand).  The method is undocumented and public 
only by accident: it is absent from `airflow.sdk.__all__`. I still added a 
deprecation shim and gave the new name a leading underscore just to be safe but 
they are likely unnecessary and the new name with the leading underscore is 
enforcing the original intent.
   
   The docs also only ever showed the shorthand version, so I have added the 
direct import-and-instantiate form to `howto/deadline-alerts.rst` along with a 
note about the contested-name case, since that is now the path a user gets 
pointed at.
   
   I split the mechanical rename, the functional name-claiming change, and the 
doc change into three different commits to hopefully make the review easier.
   
   <!-- SPDX-License-Identifier: Apache-2.0
         https://www.apache.org/licenses/LICENSE-2.0 -->
   
   <!--
   Thank you for contributing!
   
   Please provide above a brief description of the changes made in this pull 
request.
   Write a good git commit message following this guide: 
https://chris.beams.io/posts/git-commit/
   
   Please make sure that your code changes are covered with tests.
   And in case of new features or big changes remember to adjust the 
documentation.
   
   For user-facing UI changes, please attach before/after screenshots (or a 
short
   screen recording) so reviewers can assess the visual impact.
   
   Feel free to ping (in general) for the review if you do not see reaction for 
a few days
   (72 Hours is the minimum reaction time you can expect from volunteers) - we 
sometimes miss notifications.
   
   In case of an existing issue, reference it using one of the following:
   
   * closes: #ISSUE
   * related: #ISSUE
   -->
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   <!--
   If generative AI tooling has been used in the process of authoring this PR, 
please
   change below checkbox to `[X]` followed by the name of the tool, uncomment 
the "Generated-by".
   -->
   
   - [ x ] Yes (please specify the tool below)
   
   Claude Opus 5 generated the tests, which I then tweaked.
   
   <!--
   Generated-by: [Tool Name] following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   -->
   
   ---
   
   * Read the **[Pull Request 
Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)**
 for more information. Note: commit author/co-author name and email in commits 
become permanently public when merged.
   * For fundamental code changes, an Airflow Improvement Proposal 
([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals))
 is needed.
   * When adding dependency, check compliance with the [ASF 3rd Party License 
Policy](https://www.apache.org/legal/resolved.html#category-x).
   * For significant user-facing changes create newsfragment: 
`{pr_number}.significant.rst`, in 
[airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
 You can add this file in a follow-up commit after the PR is created so you 
know the PR number.
   


-- 
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