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

Check task attribute before use in sentry.add_tagging() #37143

Merged
merged 2 commits into from Mar 24, 2024

Conversation

LipuFei
Copy link
Contributor

@LipuFei LipuFei commented Feb 2, 2024

Check the the TaskInstance.task attribute before using it, because TaskInstance.task may not be set.

closes: #37142

Copy link
Collaborator

@dirrao dirrao left a comment

Choose a reason for hiding this comment

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

Can you add the test cased for the change?

Copy link
Member

@hussein-awala hussein-awala left a comment

Choose a reason for hiding this comment

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

The change looks good, but it would be better to reproduce the bug in the unit tests and confirm that it is fixed with your change, in this case we can avoid breaking it again in the future.

@LipuFei LipuFei force-pushed the fix/sentry-task-not-set branch 2 times, most recently from 661fe42 to 2b4b46c Compare February 7, 2024 12:40
@LipuFei
Copy link
Contributor Author

LipuFei commented Feb 7, 2024

@dirrao @hussein-awala I have added a test for this.

I had to refactor the sentry module because the old __init__.py makes it very difficult to test the ConfiguredSentry class. I kept the same structure and moved the 2 classes out to 2 separate files, so I can directly import ConfiguredSentry in a test.

And one more thing, I renamed DummySentry to BlankSentry because some CI check doesn't like the word "dummy"...

@eladkal eladkal added this to the Airflow 2.8.2 milestone Feb 9, 2024
@eladkal eladkal added the type:bug-fix Changelog: Bug Fixes label Feb 9, 2024
@LipuFei LipuFei force-pushed the fix/sentry-task-not-set branch 2 times, most recently from e9c9e18 to 0efee2c Compare February 16, 2024 11:00
@eladkal
Copy link
Contributor

eladkal commented Mar 18, 2024

Needs rebase and resolve conflicts

@LipuFei LipuFei force-pushed the fix/sentry-task-not-set branch 2 times, most recently from 6604fde to 6655f04 Compare March 18, 2024 12:06
@eladkal
Copy link
Contributor

eladkal commented Mar 18, 2024

@LipuFei can you fix static checks?

@LipuFei
Copy link
Contributor Author

LipuFei commented Mar 19, 2024

@LipuFei can you fix static checks?

@eladkal I will work on them.

@LipuFei LipuFei force-pushed the fix/sentry-task-not-set branch 2 times, most recently from f8e7fea to 25f348e Compare March 19, 2024 11:01
@LipuFei
Copy link
Contributor Author

LipuFei commented Mar 19, 2024

@eladkal Static checks have been fixed. 😃

@eladkal
Copy link
Contributor

eladkal commented Mar 19, 2024

Cool
@hussein-awala any further comments?

@eladkal eladkal requested a review from ferruzzi March 19, 2024 17:28
@eladkal
Copy link
Contributor

eladkal commented Mar 22, 2024

This PR marked as solving #37142
but #37142 is already solved by #37002
can you please explain?

@LipuFei
Copy link
Contributor Author

LipuFei commented Mar 22, 2024

This PR marked as solving #37142 but #37142 is already solved by #37002 can you please explain?

Hi @eladkal , this PR fixes the problem from another angle. Although the issue has been fixed, I think we can still keep this PR, because my changes make Sentry code testable. We can add some test coverage on the Sentry code.

@eladkal eladkal requested a review from potiuk March 22, 2024 13:18
@eladkal
Copy link
Contributor

eladkal commented Mar 22, 2024

This PR marked as solving #37142 but #37142 is already solved by #37002 can you please explain?

Hi @eladkal , this PR fixes the problem from another angle. Although the issue has been fixed, I think we can still keep this PR, because my changes make Sentry code testable. We can add some test coverage on the Sentry code.

OK @potiuk reviewed the first PR so lets wait for his review

@potiuk
Copy link
Member

potiuk commented Mar 22, 2024

OK @potiuk reviewed the first PR so lets wait for his review

That's just related - it's a bigger change that requires thorough -review -the original one was a quick fix. But yes - this one is more comprehensive (thouh I'd classify it as refactor not fix)

This one is hard to review due to the way Git shows it. Could you please help a bit with the review @LipuFei by making some concise way of showing what has changed between the original and new code split out ?

@potiuk
Copy link
Member

potiuk commented Mar 22, 2024

I think that would also help @eladkal and @hussein-awala to make such review.

@LipuFei
Copy link
Contributor Author

LipuFei commented Mar 22, 2024

@potiuk I will split the commits so they are easier to review.

@LipuFei
Copy link
Contributor Author

LipuFei commented Mar 23, 2024

@eladkal @potiuk @hussein-awala

Here is a summary of the changes:

  • Commit 2d1800a is to check the attribute TaskInstance.task before use.
  • Commit 24f118c is a refactor to add test:
    • DummySentry is renamed to BlankSentry due to a language check in GitHub Actions.
    • There are two Sentry classes: BlankSentry and ConfiguredSentry
      • BlankSentry is a dummy class that does nothing.
      • ConfiguredSentry actually does Sentry things.
    • Initially, both classes are in the airflow/sentry.py file. I moved BlankSentry and ConfiguredSentry out into two separate files airflow/sentry/blank.py and airflow/sentry/configured.py. The two classes are the same as before. With this refactor, I can directly import airflow/sentry/configured.py and test it. airflow/sentry/__init__.py has the same if-else-block as before.
    • Finally, I added a test tests/test_sentry.py to test ConfiguredSentry.add_tag()

@eladkal eladkal added type:improvement Changelog: Improvements and removed type:bug-fix Changelog: Bug Fixes labels Mar 23, 2024
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.

NICE. I had to do some more git comit dance and --ignore-space-change with diff helped . thanks for splitting it, that helped a bit to see that the second commit is indeed just a refactor.

@potiuk potiuk merged commit 77d2fc7 into apache:main Mar 24, 2024
46 checks passed
@LipuFei LipuFei deleted the fix/sentry-task-not-set branch March 26, 2024 19:11
Taragolis added a commit to Taragolis/airflow that referenced this pull request Mar 26, 2024
potiuk pushed a commit that referenced this pull request Mar 26, 2024
mathiaHT pushed a commit to mathiaHT/airflow that referenced this pull request Apr 4, 2024
utkarsharma2 pushed a commit to astronomer/airflow that referenced this pull request Apr 22, 2024
* Check task attribute before use in add_tagging

* Refactor sentry and add tests

---------

Co-authored-by: Lipu Fei <lipu.fei@kpn.com>
utkarsharma2 pushed a commit to astronomer/airflow that referenced this pull request Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:improvement Changelog: Improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sentry add_tagging() can take unset "task" variable
6 participants