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

ECSOperator / pass context to self.xcom_pull as it was missing (when using reattach) #17141

Merged
merged 2 commits into from
Jul 21, 2021

Conversation

pmalafosse
Copy link
Contributor

@pmalafosse pmalafosse commented Jul 21, 2021

FYI @darwinyip

This is to fix a bug I found with context not being passed to xcom_pull (used for the reattach feature)

Traceback (most recent call last):
  File "/home/airflow/.local/bin/airflow", line 8, in <module>
    sys.exit(main())
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/__main__.py", line 40, in main
    args.func(args)
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/cli/cli_parser.py", line 48, in command
    return func(*args, **kwargs)
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/cli.py", line 91, in wrapper
    return f(*args, **kwargs)
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/cli/commands/task_command.py", line 393, in task_test
    ti.run(ignore_task_deps=True, ignore_ti_state=True, test_mode=True)
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/session.py", line 70, in wrapper
    return func(*args, session=session, **kwargs)
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/models/taskinstance.py", line 1432, in run
    self._run_raw_task(
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/session.py", line 67, in wrapper
    return func(*args, **kwargs)
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/models/taskinstance.py", line 1157, in _run_raw_task
    self._prepare_and_execute_task_with_callbacks(context, task)
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/models/taskinstance.py", line 1331, in _prepare_and_execute_task_with_callbacks
    result = self._execute_task(context, task_copy)
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/models/taskinstance.py", line 1356, in _execute_task
    result = task_copy.execute(context=context)
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/session.py", line 70, in wrapper
    return func(*args, session=session, **kwargs)
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/providers/amazon/aws/operators/ecs.py", line 218, in execute
    self._try_reattach_task()
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/providers/amazon/aws/operators/ecs.py", line 309, in _try_reattach_task
    previous_task_arn = self.xcom_pull(
TypeError: xcom_pull() missing 1 required positional argument: 'context'

I updated the unit tests and ran that new code locally to make sure it was working as expected.

@o-nikolas @kaxil

@boring-cyborg boring-cyborg bot added area:providers provider:amazon AWS/Amazon - related issues labels Jul 21, 2021
@pmalafosse pmalafosse changed the title pass context to self.xcom_pull as it was missing ECSOperator / pass context to self.xcom_pull as it was missing (when using reattach) Jul 21, 2021
Copy link
Member

@potiuk potiuk left a comment

Choose a reason for hiding this comment

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

Ah cool!

@github-actions
Copy link

The PR is likely OK to be merged with just subset of tests for default Python and Database versions without running the full matrix of tests, because it does not modify the core of Airflow. If the committers decide that the full tests matrix is needed, they will add the label 'full tests needed'. Then you should rebase to the latest main or amend the last commit of the PR, and push it with --force-with-lease.

@github-actions github-actions bot added the okay to merge It's ok to merge this PR as it does not require more tests label Jul 21, 2021
Copy link
Contributor

@o-nikolas o-nikolas left a comment

Choose a reason for hiding this comment

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

Nice catch, shows how easily mocking in tests can be fraught (i.e. in this case missing the assert that context was provided). I'm curious how this got past manual testing though.

@pmalafosse
Copy link
Contributor Author

pmalafosse commented Jul 21, 2021

Nice catch, shows how easily mocking in tests can be fraught (i.e. in this case missing the assert that context was provided). I'm curious how this got past manual testing though.

this happened because in my manual testing I was using a previous version I had locally before a refactor :
context["ti"].xcom_pull(task_ids=..., key=...) to

self.xcom_pull(
            context,
            task_ids=...,
            key=...,
        )

I had to do this refactor to use mocking in the tests

@potiuk
Copy link
Member

potiuk commented Jul 21, 2021

Nice catch, shows how easily mocking in tests can be fraught (i.e. in this case missing the assert that context was provided).

It's not very well understood concept but unit tests do not replace manual tests, not even are a proof that things are right. They are there mostly to make sure that behaviour have not changed and is the same as before (so prevent regression). And having unit tests written at all (whether they are correct or not) makes it simply easier to fix things and re-run tests after we find and fix problems (and fix test afterwards :)).

@potiuk potiuk merged commit 8b100fc into apache:main Jul 21, 2021
@kaxil
Copy link
Member

kaxil commented Jul 21, 2021

Thanks 👏 @pmalafosse

@o-nikolas
Copy link
Contributor

Nice catch, shows how easily mocking in tests can be fraught (i.e. in this case missing the assert that context was provided).

It's not very well understood concept but unit tests do not replace manual tests, not even are a proof that things are right. They are there mostly to make sure that behaviour have not changed and is the same as before (so prevent regression). And having unit tests written at all (whether they are correct or not) makes it simply easier to fix things and re-run tests after we find and fix problems (and fix test afterwards :)).

Totally agree, system/E2E tests are also key for catching these types of things (i.e. functional issues) rather than the quick regression testing that unit tests provide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:providers okay to merge It's ok to merge this PR as it does not require more tests provider:amazon AWS/Amazon - related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants