Skip to content

Conversation

@BenjaminLowry
Copy link
Contributor

Before this PR

After this PR

  1. conjure-python wasn't properly handling the optional<binary> return body case from servers where if present it should be written as raw bytes and if not present the body will be empty and the return type will be 204. For an optional<binary> return type we were trying to decode the .json() field of the response which shouldn't exist in this case. So the change here is to make the isResponseBinary field check for not only the binary type but also the optional<binary> type. Also change the endpoint to return earlier if status code 204 is encountered so we can handle binary and non-binary optional return types.

  2. conjure-python wasn't handling aliases properly when it came to request/response binary types. So the change was to dealias the request/response types we were checking in the isRequestBinary and isResponseBinary args and when checking for an optional<binary> type we need to dealias both the outside and inside type as either or both could be aliases.
    ==COMMIT_MSG==
    ==COMMIT_MSG==

Possible downsides?

I believe this shouldn't break any existing use cases because using any endpoints that return optional<binary> in conjure-python should currently be failing due to trying to decode a non-existent .json() field. And similarly, any endpoints that use aliases for binary request/response types should be being handled inappropriately right now (i.e. aliases to binary are going to be treated as non-binary and thus requests will be sent with incorrect metadata, args, etc.) and non-functional.

@changelog-app
Copy link

changelog-app bot commented Jun 6, 2025

Generate changelog in changelog/@unreleased

Type (Select exactly one)

  • Feature (Adding new functionality)
  • Improvement (Improving existing functionality)
  • Fix (Fixing an issue with existing functionality)
  • Break (Creating a new major version by breaking public APIs)
  • Deprecation (Removing functionality in a non-breaking way)
  • Migration (Automatically moving data/functionality to a new system)

Description

Properly handle optional endpoint return type and binary-related aliases

Check the box to generate changelog(s)

  • Generate changelog entry

@BenjaminLowry BenjaminLowry requested a review from psyclaudeZ June 6, 2025 20:51
Copy link
Contributor

@psyclaudeZ psyclaudeZ left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for working on this!

I have a question inline which isn't about optional<binary> (I'd still prefer/recommend splitting this PR into two since they don't seem that integral, which means we could've already merged the optional<binary> one by now :p But I'm ok merging it as is given the size.)

// outer and inner type de-aliased).
.isResponseBinary(endpointDef
.getReturns()
// We do not need to handle alias of binary since they are treated differently over the wire
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this comment not make sense or has the spec changed? Sounds like it was intentionally not handling the binary alias and I'm curious of why.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The comment doesn't make sense, basically everywhere the types are de-aliased in the spec, and for binary/optional returns it's no different https://github.com/palantir/conjure/blob/master/docs/spec/wire.md#32-response-body. It further doesn't make sense that an alias of binary/optional would change the behavior of our handling of raw octet-stream data which is what the spec defines must be returned by the server in these cases. This comment is from 2018, I don't see any related change to the wire.md file that would cause this and the author is no longer at Palantir so don't know why it was there.

@BenjaminLowry BenjaminLowry requested a review from psyclaudeZ June 10, 2025 17:39
@bulldozer-bot bulldozer-bot bot merged commit 207f581 into develop Jun 10, 2025
7 checks passed
@bulldozer-bot bulldozer-bot bot deleted the blowry/optional-binary-return branch June 10, 2025 19:23
@autorelease3
Copy link

autorelease3 bot commented Jun 10, 2025

Released 4.19.0

@autorelease3
Copy link

autorelease3 bot commented Jun 10, 2025

Released 4.20.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants