Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Airflow specific warning classes #25799

Merged
merged 1 commit into from
Aug 23, 2022
Merged

Add Airflow specific warning classes #25799

merged 1 commit into from
Aug 23, 2022

Conversation

eladkal
Copy link
Contributor

@eladkal eladkal commented Aug 18, 2022

Adding RemoveInAirflow3DeprecationWarningRemovedInAirflow3Warning and AirflowProviderDeprecationWarning

RemovedInAirflow3Warning - modifying all occurrences of DeprecationWarning in core to the new class.
AirflowProviderDeprecationWarning - only adding the class. We can not yet replace warnings in providers. This will be useful when minimum provider version would be on Airflow 2.4 (or the release of this PR)

Regarding contrib folder due to the discussion of [DISCUSS] Move "contrib" and all old classes to a separate package in mailing list I left all classes untouched they will still produce DeprecationWarning

Closes: #22356

Todo:

  • Verify no missing directories (except contrib)
  • fix tests of deprecation warnings
  • We have some occurrences of PendingDeprecationWarning in the code base but I'm not sure if we have that distinction? Should we also have RemovedInAirflow3Warning ?
    Providers: Replaced all PendingDeprecationWarning with DeprecationWarning
    Core: Replaced all PendingDeprecationWarning with RemovedInAirflow3Warning

^ Add meaningful description above

Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in newsfragments.

@boring-cyborg boring-cyborg bot added provider:cncf-kubernetes Kubernetes provider related issues area:logging area:Scheduler including HA (high availability) scheduler area:secrets area:serialization labels Aug 18, 2022
airflow/configuration.py Outdated Show resolved Hide resolved
@eladkal eladkal marked this pull request as ready for review August 18, 2022 18:02
@eladkal eladkal changed the title [WIP] Add Airflow specific warning classes Add Airflow specific warning classes Aug 18, 2022
@eladkal eladkal added this to the Airflow 2.4.0 milestone Aug 18, 2022
Copy link
Member

@uranusjr uranusjr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn’t read everything

@@ -338,3 +338,17 @@ class TaskDeferralError(AirflowException):

class PodReconciliationError(AirflowException):
"""Raised when an error is encountered while trying to merge pod configs."""


class RemoveInAirflow3DeprecationWarning(DeprecationWarning):
Copy link
Member

@ashb ashb Aug 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://docs.python.org/3/library/warnings.html

DeprecationWarning Base category for warnings about deprecated features when those warnings are intended for other Python developers (ignored by default, unless triggered by code in main).
FutureWarning Base category for warnings about deprecated features when those warnings are intended for end users of applications that are written in Python.
-- --
PendingDeprecationWarning Base category for warnings about features that will be deprecated in the future (ignored by default).
-- --

Should we make this baseclass be FutureWarning?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We consider Airflow users as Python developers not end users don't we?

Copy link
Contributor

@blag blag Aug 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PendingDeprecationWarnings and DeprecationWarnings are filtered out by default. I think subclassing from FutureWarning would make them more visible to Airflow DAG authors.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, we may not want this to be immediately visible to DAG authors, because at this point we should still assume that we will only have 2.x releases.

Subclassing from DeprecationWarning (or PendingDeprecationWarning) might actually be the right call here until we have concrete plans for Airflow 3.0. PEP-0387:

If an API is being removed, simply warn whenever it is entered. DeprecationWarning is the usual warning category to use, but PendingDeprecationWarning may be used in special cases where the old and new versions of the API will coexist for many releases [2].

(emphasis mine)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We explicitly enable the Deprecation warnings coming from airflow following https://peps.python.org/pep-0565/#recommended-filter-settings-for-interactive-shells

See airflow.configuration.py:

if not sys.warnoptions:
    warnings.filterwarnings(action='default', category=DeprecationWarning, module='airflow')
    warnings.filterwarnings(action='default', category=PendingDeprecationWarning, module='airflow')

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious why #1285 "turned on" both DeprecationWarning and PendingDeprecationWarning.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was 6 years ago :) 5 Apr 2016 :). I am afraid no commiters who are active now were even around :D

Copy link
Contributor

@zachliu zachliu Aug 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry to comment here, but i'm obsessed with DeprecationWarning recently because i couldn't find mine 😂 :
https://apache-airflow.slack.com/archives/CSS36QQS1/p1661974104498239

airflow/exceptions.py Outdated Show resolved Hide resolved
@potiuk
Copy link
Member

potiuk commented Aug 22, 2022

Comment: We COULD potentially do the same approach as with common.sql and introduce 'apache-airflow-providers-common-provider` and add the AirflowProviderDeprecationWarning.

If the package is very small, we can keep it as a way to add functionality that is common to all providers.

And we could replace the provider's warnings even now.

@potiuk
Copy link
Member

potiuk commented Aug 22, 2022

Should we add a pre-commit to check automatically if there are no "standard" warnings in Airflow code? I think it should be as easy as using pygrep pre-commit (we already use it in a few places).

@eladkal
Copy link
Contributor Author

eladkal commented Aug 23, 2022

And we could replace the provider's warnings even now.

We can but to be honest I think it has very little value. With the new provider governance module there is no reason to keep deprecations for so long. We can remove them really fast even in a follow up release with is 1 month window and cherry pick features to earlier releases.
Also, after 2.4 is minimum Airflow version for providers you probably won't need apache-airflow-providers-common-provider to store the deprecation class as you will just import it from core so I don't think it's worth the effort

@eladkal
Copy link
Contributor Author

eladkal commented Aug 23, 2022

Should we add a pre-commit to check automatically if there are no "standard" warnings in Airflow code? I think it should be as easy as using pygrep pre-commit (we already use it in a few places).

Added

Adding `RemoveInAirflow3DeprecationWarning` and `AirflowProviderDeprecationWarning`

Closes: apache#22356
@eladkal eladkal requested a review from blag August 23, 2022 10:15
@potiuk potiuk merged commit 1a1f352 into apache:main Aug 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:logging area:Scheduler including HA (high availability) scheduler area:secrets area:serialization provider:cncf-kubernetes Kubernetes provider related issues type:new-feature Changelog: New Features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change DeprecationWarning to AirflowDeprecationWarning
7 participants