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

Fix log endpoint for same task #19672

Merged
merged 5 commits into from
Nov 22, 2021

Conversation

humit0
Copy link
Contributor

@humit0 humit0 commented Nov 18, 2021

Log endpoint API raise exception when same task_id with different dag_id.

Traceback (most recent call last):
  File "/opt/app-root/lib64/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/opt/app-root/lib64/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/opt/app-root/lib64/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/opt/app-root/lib64/python3.8/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/opt/app-root/lib64/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/opt/app-root/lib64/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/opt/app-root/lib64/python3.8/site-packages/airflow/_vendor/connexion/decorators/decorator.py", line 48, in wrapper
    response = function(request)
  File "/opt/app-root/lib64/python3.8/site-packages/airflow/_vendor/connexion/decorators/uri_parsing.py", line 144, in wrapper
    response = function(request)
  File "/opt/app-root/lib64/python3.8/site-packages/airflow/_vendor/connexion/decorators/validation.py", line 384, in wrapper
    return function(request)
  File "/opt/app-root/lib64/python3.8/site-packages/airflow/_vendor/connexion/decorators/response.py", line 103, in wrapper
    response = function(request)
  File "/opt/app-root/lib64/python3.8/site-packages/airflow/_vendor/connexion/decorators/parameter.py", line 121, in wrapper
    return function(**kwargs)
  File "/opt/app-root/lib64/python3.8/site-packages/airflow/api_connexion/security.py", line 47, in decorated
    return func(*args, **kwargs)
  File "/opt/app-root/lib64/python3.8/site-packages/airflow/utils/session.py", line 70, in wrapper
    return func(*args, session=session, **kwargs)
  File "/opt/app-root/lib64/python3.8/site-packages/airflow/api_connexion/endpoints/log_endpoint.py", line 64, in get_log
    session.query(TaskInstance)
  File "/opt/app-root/lib64/python3.8/site-packages/sqlalchemy/orm/query.py", line 3467, in one_or_none
    raise orm_exc.MultipleResultsFound(
sqlalchemy.orm.exc.MultipleResultsFound: Multiple rows were found for one_or_none()

So, I add dag_id filter to get unique task_instance.


^ Add meaningful description above

Read the Pull Request Guidelines for more information.
In case of fundamental code change, 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 UPDATING.md.

@boring-cyborg boring-cyborg bot added the area:API Airflow's REST/HTTP API label Nov 18, 2021
@uranusjr
Copy link
Member

Good catch! But please don’t change the tests—duplication is somewhat intentional there.

https://evgenii.com/blog/code-duplication-in-unit-tests/

@humit0
Copy link
Contributor Author

humit0 commented Nov 18, 2021

Good catch! But please don’t change the tests—duplication is somewhat intentional there.

https://evgenii.com/blog/code-duplication-in-unit-tests/

You mean revert fbd054d commits? If so, I will revert that commit.

I use RUN_ID because other parts (dag_id, task_id) are using as variable when create API URL.

@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 Nov 22, 2021
@uranusjr uranusjr merged commit abbebad into apache:main Nov 22, 2021
@humit0 humit0 deleted the fix-log-endpoint-for-same-task-id branch November 29, 2021 00:50
@jedcunningham jedcunningham added this to the Airflow 2.2.3 milestone Dec 7, 2021
jedcunningham pushed a commit that referenced this pull request Dec 7, 2021
Co-authored-by: huan.15 <huan.15@kakaocorp.com>
(cherry picked from commit abbebad)
@jedcunningham jedcunningham added the type:bug-fix Changelog: Bug Fixes label Dec 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:API Airflow's REST/HTTP API okay to merge It's ok to merge this PR as it does not require more tests type:bug-fix Changelog: Bug Fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants