-
Notifications
You must be signed in to change notification settings - Fork 16.3k
Replaced all days_ago functions with datetime functions #21796
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,7 +34,6 @@ | |
| from airflow.models.taskinstance import SimpleTaskInstance | ||
| from airflow.operators.dummy import DummyOperator | ||
| from airflow.utils import timezone | ||
| from airflow.utils.dates import days_ago | ||
| from airflow.utils.session import create_session | ||
| from airflow.utils.state import State | ||
| from airflow.utils.types import DagRunType | ||
|
|
@@ -113,7 +112,7 @@ def test_dag_file_processor_sla_miss_callback(self, create_dummy_dag): | |
|
|
||
| # Create dag with a start of 1 day ago, but an sla of 0 | ||
| # so we'll already have an sla_miss on the books. | ||
| test_start_date = days_ago(1) | ||
| test_start_date = datetime.datetime(2022, 1, 1) | ||
| dag, task = create_dummy_dag( | ||
| dag_id='test_sla_miss', | ||
| task_id='dummy', | ||
|
|
@@ -142,7 +141,7 @@ def test_dag_file_processor_sla_miss_callback_invalid_sla(self, create_dummy_dag | |
| # Create dag with a start of 1 day ago, but an sla of 0 | ||
| # so we'll already have an sla_miss on the books. | ||
| # Pass anything besides a timedelta object to the sla argument. | ||
| test_start_date = days_ago(1) | ||
| test_start_date = datetime.datetime(2022, 1, 1) | ||
| dag, task = create_dummy_dag( | ||
| dag_id='test_sla_miss', | ||
| task_id='dummy', | ||
|
|
@@ -170,7 +169,7 @@ def test_dag_file_processor_sla_miss_callback_sent_notification(self, create_dum | |
|
|
||
| # Create dag with a start of 2 days ago, but an sla of 1 day | ||
| # ago so we'll already have an sla_miss on the books | ||
| test_start_date = days_ago(2) | ||
| test_start_date = datetime.datetime(2022, 1, 1) | ||
| dag, task = create_dummy_dag( | ||
| dag_id='test_sla_miss', | ||
| task_id='dummy', | ||
|
|
@@ -206,7 +205,7 @@ def test_dag_file_processor_sla_miss_doesnot_raise_integrity_error(self, dag_mak | |
|
|
||
| # Create dag with a start of 2 days ago, but an sla of 1 day | ||
| # ago so we'll already have an sla_miss on the books | ||
| test_start_date = days_ago(2) | ||
| test_start_date = datetime.datetime(2022, 1, 1) | ||
| with dag_maker( | ||
| dag_id='test_sla_miss', | ||
| default_args={'start_date': test_start_date, 'sla': datetime.timedelta(days=1)}, | ||
|
|
@@ -247,7 +246,7 @@ def test_dag_file_processor_sla_miss_callback_exception(self, mock_stats_incr, c | |
|
|
||
| sla_callback = MagicMock(side_effect=RuntimeError('Could not call function')) | ||
|
|
||
| test_start_date = days_ago(2) | ||
| test_start_date = datetime.datetime(2022, 1, 1) | ||
| dag, task = create_dummy_dag( | ||
| dag_id='test_sla_miss', | ||
| task_id='dummy', | ||
|
|
@@ -277,7 +276,7 @@ def test_dag_file_processor_only_collect_emails_from_sla_missed_tasks( | |
| ): | ||
| session = settings.Session() | ||
|
|
||
| test_start_date = days_ago(2) | ||
| test_start_date = datetime.datetime(2022, 1, 1) | ||
| email1 = '[email protected]' | ||
| dag, task = create_dummy_dag( | ||
| dag_id='test_sla_miss', | ||
|
|
@@ -317,7 +316,7 @@ def test_dag_file_processor_sla_miss_email_exception( | |
| # Mock the callback function so we can verify that it was not called | ||
| mock_send_email.side_effect = RuntimeError('Could not send an email') | ||
|
|
||
| test_start_date = days_ago(2) | ||
| test_start_date = datetime.datetime(2022, 1, 1) | ||
| dag, task = create_dummy_dag( | ||
| dag_id='test_sla_miss', | ||
| task_id='dummy', | ||
|
|
@@ -347,7 +346,7 @@ def test_dag_file_processor_sla_miss_deleted_task(self, create_dummy_dag): | |
| """ | ||
| session = settings.Session() | ||
|
|
||
| test_start_date = days_ago(2) | ||
| test_start_date = datetime.datetime(2022, 1, 1) | ||
| dag, task = create_dummy_dag( | ||
| dag_id='test_sla_miss', | ||
| task_id='dummy', | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,13 +16,12 @@ | |
| # specific language governing permissions and limitations | ||
| # under the License. | ||
| from datetime import timedelta | ||
|
|
||
| import datetime | ||
|
Comment on lines
18
to
+19
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If and use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh! didn't see that there. There are a lot of files and I checked each one manually for maximum efficiency so forgot to use some of the already present libraries. If you want I can change them again quickly |
||
| from airflow.models import DAG | ||
| from airflow.operators.bash import BashOperator | ||
| from airflow.operators.dummy import DummyOperator | ||
| from airflow.utils.dates import days_ago | ||
|
|
||
| args = {'owner': 'airflow', 'retries': 3, 'start_date': days_ago(2)} | ||
| args = {'owner': 'airflow', 'retries': 3, 'start_date': datetime.datetime(2022,1,1)} | ||
|
|
||
| dag = DAG( | ||
| dag_id='test_example_bash_operator', | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect we should move away from
datetime.datetimetopendulum.datetimeforstart_datevalues in unit tests too based on the conversation in #21646. @eladkal WDYT?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean just for tests or also for example dags?
I have no objection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For unit tests as well as example DAGs for consistency in tests, examples, docs, etc. The core example DAGs have been transitioned but the provider ones haven't yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I too think pendulum is a better alternative for datetime
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then yeah lets do that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course! Not a problem at all
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
80a6ae5
Another pull request after swapping datetime with pendulum where start dates are involved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For tests specifically I actually prefer
datetime.datetimesince it better ensures we are coercing timezones correctly internally.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That one is also done in the previous pull request. I guess my task is done so please let me know if there is anything more to update.