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 JSON decoding error when empty optional is returned. #16

Merged
merged 5 commits into from
Sep 10, 2018

Conversation

tom-s-powell
Copy link
Contributor

Let me know if you'd prefer some kind of helper to be pulled out.

Copy link
Contributor

@ferozco ferozco left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! I think that we may want to make this change in conjure-python-client instead though.

I'd like to keep the generator as simple as possible, and this would further leak details of the requests implementation into to the generic code gen

@tom-s-powell
Copy link
Contributor Author

tom-s-powell commented Aug 6, 2018

@ferozco I thought about this. This would mean moving the Conjure decoding into the client or having the client at least have some knowledge of the return type (assuming you wouldn't want to return None if response.status_code == 204 else response) since you'd have to handle the binary vs JSON case somewhere. Are you fine with that?

@iamdanfox
Copy link
Contributor

@tom-s-powell I've just enabled CircleCI's build forks setting, so you should get builds from now on!

screen shot 2018-08-07 at 13 03 56

@iamdanfox iamdanfox closed this Aug 7, 2018
@iamdanfox iamdanfox reopened this Aug 7, 2018
@ferozco
Copy link
Contributor

ferozco commented Aug 8, 2018

I think you're right @tom-s-powell, for now this is probably the best way forward

@iamdanfox
Copy link
Contributor

iamdanfox commented Aug 16, 2018

I'd really like to get the proper test cases implemented before we merge this... I think we'll need to build some dedicated endpoints on the verification-server that will return 204s for map, list and set returns (and also alias of map, list and set).

Tracking here: palantir/conjure-verification#38

@tom-s-powell
Copy link
Contributor Author

@iamdanfox is there a timeline on this change in conjure-verification?

@qinfchen
Copy link

qinfchen commented Aug 31, 2018

@tom-s-powell, there is a pr for this, palantir/conjure-verification#44

@@ -88,6 +88,9 @@ public PythonClass generateClient(
}
return false;
}).orElse(false))
.isOptionalReturnType(ed.getReturns()
.map(rt -> rt.accept(TypeVisitor.IS_OPTIONAL))
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't work on the test-case for this in conjure-verification 0.10.0 because it is an alias to an optional type. This type visitor is used in a handful of places to determine whether or not a value is optional. Should the visitor also return true if the type is an alias to an optional? Should there be a separate visitor which handles the alias case?

  {
    "type" : "alias",
    "alias" : {
      "typeName" : {
        "name" : "RawOptionalExample",
        "package" : "com.palantir.conjure.verification"
      },
      "alias" : {
        "type" : "optional",
        "optional" : {
          "itemType" : {
            "type" : "primitive",
            "primitive" : "INTEGER"
          }
        }
      }
    }
  }

Copy link
Contributor

Choose a reason for hiding this comment

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

@ferozco @iamdanfox I'm not actually sure what the right thing to do is

Copy link
Contributor

Choose a reason for hiding this comment

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

We encountered something similar in conjure-core and made: https://github.com/palantir/conjure/blob/develop/conjure-core/src/main/java/com/palantir/conjure/defs/DealiasingTypeVisitor.java . Perhaps we can factor that out into the generator commons and you can then use it here

Copy link
Contributor

Choose a reason for hiding this comment

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

👍 would really like to see that in generator-commons

Copy link
Contributor

Choose a reason for hiding this comment

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

4.2.0 is out with the new visitor

@ahggns
Copy link
Contributor

ahggns commented Sep 5, 2018

Tests are blocking on palantir/conjure-verification#45

@ahggns
Copy link
Contributor

ahggns commented Sep 6, 2018

It wasn't that the verification server doesn't accept null, I think its probably that python requests doesn't send a body when the json argument is None, and the verification server's Json parsing doesn't like that:

$ curl -s http://localhost:8000/confirm/receiveRawOptionalExample/0 -XPOST -H 'content-type: application/json'                                                                        
{"errorCode":"INVALID_ARGUMENT","errorName":"Conjureverification:InvalidRequestBody","errorInstanceId":"ec3a4ec0-4bbd-42da-8058-14357fb1014a","parameters":{}}%

@iamdanfox
Copy link
Contributor

Chatting in person, I've filed #18 to make sure we finish off the tests here, without blocking these guys too much!

@iamdanfox iamdanfox merged commit 4f0fc3a into palantir:develop Sep 10, 2018
@iamdanfox iamdanfox deleted the tp/fix-optional-return branch September 10, 2018 16:02
derenrich pushed a commit to derenrich/conjure-python that referenced this pull request Jan 8, 2019
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.

6 participants