Skip to content

Swallowed return_value in record_subsegment(...)? #43

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

Closed
nelz9999 opened this issue Mar 20, 2018 · 1 comment
Closed

Swallowed return_value in record_subsegment(...)? #43

nelz9999 opened this issue Mar 20, 2018 · 1 comment
Labels

Comments

@nelz9999
Copy link
Contributor

My Python may not be super strong, but in my reading of try: except: finally:, it seems that the return_value is being trashed in the LOG_ERROR case.

From https://github.com/aws/aws-xray-sdk-python/blob/master/aws_xray_sdk/core/recorder.py:

        return_value = None

        try:
            return_value = wrapped(*args, **kwargs)
            return return_value
        except Exception as e:
            exception = e
            stack = traceback.extract_stack(limit=self._max_trace_back)
            raise
        finally:
            # No-op if subsegment is `None` due to `LOG_ERROR`.
            if subsegment is None:
                return

Isn't that last return actually equivalent to return None?

@haotianw465
Copy link
Contributor

You are absolutely right. It should be

        return_value = None

        try:
            return_value = wrapped(*args, **kwargs)
            return return_value
        except Exception as e:
            exception = e
            stack = traceback.extract_stack(limit=self._max_trace_back)
            raise
        finally:
            # No-op if subsegment is `None` due to `LOG_ERROR`.
            if subsegment is None:
                return return_value

We have a unit test cover this scenario but unfortunately that unit test fails to check the return value. See https://github.com/aws/aws-xray-sdk-python/blob/master/tests/ext/botocore/test_botocore.py#L107.

Feel free to submit a PR and I can merge it as soon as possible. But regardless we will make sure this will be fixed in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants