-
Notifications
You must be signed in to change notification settings - Fork 14.5k
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-2508] Handle non string types in Operators templatized fields #4292
[AIRFLOW-2508] Handle non string types in Operators templatized fields #4292
Conversation
b3a597e
to
0421823
Compare
776eed7
to
ac020a7
Compare
ac020a7
to
c1230ef
Compare
Codecov Report
@@ Coverage Diff @@
## master #4292 +/- ##
==========================================
- Coverage 74.1% 74.03% -0.08%
==========================================
Files 421 421
Lines 27681 28059 +378
==========================================
+ Hits 20514 20773 +259
- Misses 7167 7286 +119
Continue to review full report at Codecov.
|
c1230ef
to
798c79e
Compare
798c79e
to
77e30bc
Compare
I rebased my PR onto master. Is there something more I should do so that this PR can be reviewed ? |
Could you give an example where this is used in a DAG so we can see it in context? I also wonder if it is worth noting something about this in the docs? |
tests/models.py
Outdated
from tempfile import NamedTemporaryFile, mkdtemp | ||
|
||
import pendulum | ||
import six | ||
from hamcrest import contains, instance_of | ||
from hamcrest.core import assert_that | ||
from hamcrest.core.core import is_ |
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.
Please just use the built in assert methods assertIsIn
, assertIsInstanceOf
etc.
tests/models.py
Outdated
task = DummyOperator(task_id='op1') | ||
|
||
random_uuid = uuid.uuid4() | ||
assert_that(task.render_template('', random_uuid, dict(foo='bar')), is_(random_uuid)) |
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.
assert_that(task.render_template('', random_uuid, dict(foo='bar')), is_(random_uuid)) | |
assert_that(task.render_template('', random_uuid, {'foo':'bar'}), is_(random_uuid)) |
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.
Elsewhere too - please us {}
rather than dict()
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.
See comments.
An example can be found in AIRFLOW-2508 Jira ticket description. But I can provide an additional one here if required. Just let me know
You're right! My bad, I forgot about it. I will update render_template_from_field method documentation |
Code and test looks broadly good though. Please ping me once requested changes have been made. |
Thank you! And also thank you for reviewing my code! Quick question : should I squash all my commits together again before submitting requested changes? |
We'll squash before merging in †he GitHub interface so it doesn't make any difference to us. My personal preference is to see fixup! commits if you are comfortable with that, then I can look at just the fixup changes. But a PR this size I don't mind just a force-push of a single new commit either. |
Hi @ashb, I'm done with my changes. |
Jira
This PR addresses [AIRFLOW-2508] Handle non string types in render_template_from_field
Description
This PR changes
BaseOperator.render_template_from_field
method behavior:string_types
and supportingNumber
s (and collections or dictionaries of these types); but it was raising anAirflowException
on any other type.Tests
This PR adds the following unit tests on
BaseOperator.render_template_from_field
method:date
as isdatetime
as isUUID
as isobject
as isNotice
This PR adds pyhamcrest to Airflow test dependencies. This module helps writing meaningful assertions, and also provides very clear and helpful messages on test failures.
If Airflow maintainers do not want to include this test module, just let me know, and I'll rework unit tests
Note
This PR was made during working hours thanks to my employer: the city of Montreal