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

[AIRFLOW-4490] DagRun.conf should return empty dictionary by default #5388

Conversation

dstandish
Copy link
Contributor

@dstandish dstandish commented Jun 7, 2019

Currently, we can access dag_run.conf in templates like so:

 "{{ dag_run.conf.get('abc', 'def_val') }}"

But if no conf is passed to the dag run, the above jinja template will fail upon rendering, because conf will be None.

So currently, to be safe, you have to do this:

 "{{ dag_run.conf and dag_run.conf.get('abc', 'def_val') }}"

This PR changes DagRun model so that it returns an empty dictionary when there is no conf.

Jira

  • My PR addresses the following Airflow Jira issues and references them in the PR title. For example, "[AIRFLOW-XXX] My Airflow PR"
    • https://issues.apache.org/jira/browse/AIRFLOW-XXX
    • In case you are fixing a typo in the documentation you can prepend your commit with [AIRFLOW-XXX], code changes always need a Jira issue.
    • In case you are proposing a fundamental code change, you need to create an Airflow Improvement Proposal (AIP).
    • In case you are adding a dependency, check if the license complies with the ASF 3rd Party License Policy.

Description

  • Here are some details about my PR, including screenshots of any UI changes:

Tests

  • My PR adds the following unit tests OR does not need testing for this extremely good reason:

Commits

  • My commits all reference Jira issues in their subject lines, and I have squashed multiple commits if they address the same issue. In addition, my commits follow the guidelines from "How to write a good git commit message":
    1. Subject is separated from body by a blank line
    2. Subject is limited to 50 characters (not including Jira issue reference)
    3. Subject does not end with a period
    4. Subject uses the imperative mood ("add", not "adding")
    5. Body wraps at 72 characters
    6. Body explains "what" and "why", not "how"

Documentation

  • In case of new functionality, my PR adds documentation that describes how to use it.
    • All the public functions and the classes in the PR contain docstrings that explain what it does
    • If you implement backwards incompatible changes, please leave a note in the Updating.md so we can assign it to a appropriate release

Code Quality

  • Passes flake8

@dstandish dstandish force-pushed the feature/dag_run.conf-default-empty-dict branch 2 times, most recently from 578073a to a91847e Compare June 8, 2019 06:18
@codecov-io
Copy link

codecov-io commented Jun 8, 2019

Codecov Report

Merging #5388 into master will decrease coverage by 0.28%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5388      +/-   ##
==========================================
- Coverage    84.7%   84.41%   -0.29%     
==========================================
  Files         679      679              
  Lines       38488    38494       +6     
==========================================
- Hits        32600    32496     -104     
- Misses       5888     5998     +110
Impacted Files Coverage Δ
airflow/models/dagrun.py 96.68% <100%> (+0.09%) ⬆️
airflow/kubernetes/volume_mount.py 44.44% <0%> (-55.56%) ⬇️
airflow/kubernetes/volume.py 52.94% <0%> (-47.06%) ⬇️
airflow/kubernetes/pod_launcher.py 45.25% <0%> (-46.72%) ⬇️
airflow/kubernetes/refresh_config.py 50.98% <0%> (-23.53%) ⬇️
...rflow/contrib/operators/kubernetes_pod_operator.py 78.75% <0%> (-20%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5e100ab...654a62a. Read the comment docs.

airflow/models/skipmixin.py Outdated Show resolved Hide resolved
tests/models/test_taskinstance.py Outdated Show resolved Hide resolved
tests/models/test_taskinstance.py Outdated Show resolved Hide resolved
tests/models/test_taskinstance.py Outdated Show resolved Hide resolved
airflow/models/dagrun.py Outdated Show resolved Hide resolved
@dstandish dstandish force-pushed the feature/dag_run.conf-default-empty-dict branch from a91847e to d908ff8 Compare June 11, 2019 19:18
@dstandish
Copy link
Contributor Author

I got rid of the change to template context, which initially provided an empty DagRun() object if no dag run. Accordingly this PR no longer touches skip mixin.

@stale
Copy link

stale bot commented Sep 3, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Stale PRs per the .github/workflows/stale.yml policy file label Sep 3, 2019
@OmerJog
Copy link
Contributor

OmerJog commented Sep 4, 2019

@dstandish can you rebase?

@stale stale bot removed the stale Stale PRs per the .github/workflows/stale.yml policy file label Sep 4, 2019
@dstandish
Copy link
Contributor Author

@OmerJog I just resolved conflicts using github's "resolve conflicts" thing -- i will rebase and squash later this week.

What do you think is the better approach? This or #5387?

#5387 adds a "dag_run_conf" to context. The nice thing about that approach is then it doesn't fail when there is no dag_run (i.e. when you are just testing template rendering in interactive console).

If you still think this is valuable I can mention it in #development slack chat -- I don't really use dag run conf anymore so I lost interest.

@dstandish
Copy link
Contributor Author

dstandish commented Sep 4, 2019

@OmerJog also you are welcome to take this over and do the rebase and do the squeaky-wheeling if you want :)

@OmerJog
Copy link
Contributor

OmerJog commented Oct 17, 2019

@dstandish tests did not run because of Falke8 error:
tests/models/test_taskinstance.py:1285:1: W293 blank line contains whitespace

can you resolve this?

@dstandish dstandish force-pushed the feature/dag_run.conf-default-empty-dict branch from f5e572a to f377c64 Compare October 28, 2019 07:42
@dstandish
Copy link
Contributor Author

dstandish commented Oct 28, 2019

@dstandish tests did not run because of Falke8 error:
tests/models/test_taskinstance.py:1285:1: W293 blank line contains whitespace

can you resolve this?

@OmerJog rebased. passed flake8 locally.

@OmerJog
Copy link
Contributor

OmerJog commented Nov 15, 2019

@ashb ping :)

@tooptoop4
Copy link
Contributor

stale block

@dstandish dstandish force-pushed the feature/dag_run.conf-default-empty-dict branch from f377c64 to 654a62a Compare December 30, 2019 00:06
@dstandish dstandish changed the title [AIRFLOW-4490] DagRun.conf returns empty dictionary by default [AIRFLOW-4490] DagRun.conf should return empty dictionary by default Jan 13, 2020
@stale
Copy link

stale bot commented Feb 27, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Stale PRs per the .github/workflows/stale.yml policy file label Feb 27, 2020
@stale stale bot closed this Mar 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Stale PRs per the .github/workflows/stale.yml policy file
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants