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

v0.9.4 breaks the returns.json decorator with type=int #215

Closed
nilsvu opened this issue Feb 16, 2021 · 9 comments
Closed

v0.9.4 breaks the returns.json decorator with type=int #215

nilsvu opened this issue Feb 16, 2021 · 9 comments
Assignees

Comments

@nilsvu
Copy link
Contributor

nilsvu commented Feb 16, 2021

Before v0.9.4 this code worked and converted the JSON field to an int:

    @uplink.returns.json(key=('metadata', 'length'), type=int)
    @uplink.get('records/{id}')
    def get_record_length(self, record_id: uplink.Path(name='id')):
        pass

With v0.9.4 the endpoint returns a <Response [200]> object instead of the expected int.

Am I not using the type argument of returns.json as intended? It would be very useful to be able to do simple type conversions such as this without having to write a model.

@prkumar prkumar self-assigned this Feb 17, 2021
@Imaclean74
Copy link

I see the same thing. Didn’t realize that this used to work.

@prkumar
Copy link
Owner

prkumar commented Jan 8, 2022

I have PR #229 prepped to fix this issue.

prkumar added a commit that referenced this issue Jan 8, 2022
…229)

Fix ``@returns.json`` to cast JSON response (or field referenced by the ``key`` argument) using the ``type`` argument when the given type is callable. This restores behavior that was inadvertently changed in v0.9.3.

Example:

```python
  @uplink.returns.from_json(key=("data", 0, "size"), type=int)
  @uplink.get("/users/{user}/repos")
  def get_first_repo_size(self, user):
      pass
```

```python
assert github.get_first_repo_size("prkumar") == 300
```

#215
@prkumar
Copy link
Owner

prkumar commented Jan 9, 2022

I've merged #229, so this should be fixed in the next minor release. I'm planning to conduct a release for v0.9.6 sometime in the next week.

@prkumar
Copy link
Owner

prkumar commented Jan 9, 2022

Here's the tentative CHANGELOG entry:

  • Fix @returns.json to cast the JSON response (or field referenced by the key argument) using the type argument when it is a callable type. This effectively reverts a change in the decorator's behavior that was introduced in v0.9.3.

Let me know if anyone has any thoughts on the entry's clarity. I'm hoping the above message conveys the change's impact succinctly.

@prkumar prkumar mentioned this issue Jan 24, 2022
@prkumar
Copy link
Owner

prkumar commented Jan 29, 2022

This issue should be fixed in v0.9.6

@prkumar prkumar removed this from the v0.9.5 milestone Jan 29, 2022
@prkumar prkumar closed this as completed Jan 29, 2022
@leiserfg
Copy link
Contributor

leiserfg commented Feb 1, 2022

This is also happening for Header

@prkumar
Copy link
Owner

prkumar commented Feb 2, 2022

@leiserfg - Can you provide a code sample to help reproduce? Also, could you explain the expected and actual behaviors you are seeing with Header?

Thanks!

@leiserfg
Copy link
Contributor

leiserfg commented Feb 2, 2022

I was using it to automatically add the prefix to the token as from certain endpoint I was getting it without it (the "Bearer " part). Maybe I was abusing the API but it worked fine until that change.

@prkumar
Copy link
Owner

prkumar commented Feb 6, 2022

@leiserfg - Got it. If I understand correctly, you were using Header for something like this:

def addBearerToken(token):
    return "Bearer " + token

@uplink.get('user')
def get_user(self, bearer_token: Header(type=addBearerPrefix)):
    pass

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

No branches or pull requests

4 participants