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 overly broad exception conversion in LambdaFunction.invoke #6394

Merged
merged 2 commits into from
Jul 10, 2023

Conversation

SpecLad
Copy link
Contributor

@SpecLad SpecLad commented Jun 28, 2023

Motivation and context

The intent of the try/except statement is to catch accesses to missing members of the data dictionary, but due to the large amount of code in the try block, it may end up catching entirely unrelated KeyErrors. Those unrelated KeyErrors should not be converted to ValidationErrors, since they might not have anything to do with input validation, and the conversion will make it harder to debug these exceptions.

An example of these misapplied conversions is a recent bug where a KeyError was coming from inside _get_image (fixed by f6420eb).

To fix this, make sure to only catch KeyErrors emitted by accesses to data.

How has this been tested?

I manually checked that a) invoking functions still works, and b) omitting required parameters still results in a 400 error.

Checklist

  • I submit my changes into the develop branch
  • I have added a description of my changes into the CHANGELOG file
  • [ ] I have updated the documentation accordingly
  • [ ] I have added tests to cover my changes
  • I have linked related issues (see GitHub docs)
  • [ ] I have increased versions of npm packages if it is necessary
    (cvat-canvas,
    cvat-core,
    cvat-data and
    cvat-ui)

License

  • I submit my code changes under the same MIT License that covers the project.
    Feel free to contact the maintainers if that's a concern.

@SpecLad SpecLad requested a review from Marishka17 as a code owner June 28, 2023 12:11
The intent of the `try`/`except` statement is to catch accesses to missing
members of the `data` dictionary, but due to the large amount of code in the
`try` block, it may end up catching entirely unrelated `KeyError`s. Those
unrelated `KeyError`s should not be converted to `ValidationError`s, since
they might not have anything to do with input validation, and the conversion
will make it harder to debug these exceptions.

An example of these misapplied conversions is a recent bug where a `KeyError`
was coming from inside `_get_image` (fixed by f6420eb).

To fix this, make sure to only catch `KeyError`s emitted by accesses to
`data`.
@zhiltsov-max
Copy link
Contributor

Please check if this needs a new test in this application tests.

@codecov
Copy link

codecov bot commented Jun 28, 2023

Codecov Report

Merging #6394 (4d91f8c) into develop (d950d24) will decrease coverage by 6.74%.
The diff coverage is 0.00%.

@@             Coverage Diff             @@
##           develop    #6394      +/-   ##
===========================================
- Coverage    80.04%   73.30%   -6.74%     
===========================================
  Files          332      316      -16     
  Lines        38438    37538     -900     
  Branches      6923     6726     -197     
===========================================
- Hits         30767    27519    -3248     
- Misses        7355     9191    +1836     
- Partials       316      828     +512     
Components Coverage Δ
cvat-ui 72.72% <ø> (-0.65%) ⬇️
cvat-server 73.82% <0.00%> (-12.41%) ⬇️

@SpecLad
Copy link
Contributor Author

SpecLad commented Jun 28, 2023

Please check if this needs a new test in this application tests.

I don't think this change is testable, because it only makes a difference when there's an internal error in CVAT - which isn't supposed to happen.

@SpecLad SpecLad merged commit 44382be into cvat-ai:develop Jul 10, 2023
@SpecLad SpecLad deleted the keyerror-catch branch July 10, 2023 12:55
mikhail-treskin pushed a commit to retailnext/cvat that referenced this pull request Oct 25, 2023
…t-ai#6394)

The intent of the `try`/`except` statement is to catch accesses to
missing members of the `data` dictionary, but due to the large amount of
code in the `try` block, it may end up catching entirely unrelated
`KeyError`s. Those unrelated `KeyError`s should not be converted to
`ValidationError`s, since they might not have anything to do with input
validation, and the conversion will make it harder to debug these
exceptions.

An example of these misapplied conversions is a recent bug where a
`KeyError` was coming from inside `_get_image` (fixed by f6420eb).

To fix this, make sure to only catch `KeyError`s emitted by accesses to
`data`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants