-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Invalid cast on Deployment.Create #2250
Comments
I'm running into this too. Definitely looks like a bug. The question is does the GitHub API do anything with the Otherwise it might make sense to change |
Actually, probably needs to be a string since the Payload field can be created by other clients. I know the ruby client just lets you set that as a string. In order to be able to use this client to load deployments created by other clients, we can't assume they put it in a format deserializable to a dictionary. |
Ah, changing it to a string probably won't help. The issue is that the serializer doesn't know that [Fact]
public void CanSerialize()
{
var deployment = new NewDeployment("ref")
{
Payload = @"{ ""environment"":""production""}"
};
var deserialized = new SimpleJsonSerializer().Serialize(deployment);
Assert.Equal(@"{""ref"":""ref"",""task"":""deploy"",""payload"":""{ \""environment\"":\""production\""}""}", deserialized);
} That's why it can't round trip it. I wonder if there's a way to tell JSON.NET to treat that property as raw JSON and don't encode it. |
Ok, after digging into the code, I forgot that Octokit.net uses a simple serializer that doesn't embed type info. So I think the easy fix is to change |
When serializing the `NewDeployment` type, the `Payload` is serialized as an escaped string because JSON.NET doesn't know it's meant to be JSON. This causes a problem when you call the API because the Payload is supposed to be a JSON dictionary that's just part of the overall payload. It's not supposed to be an escaped string. That's why the JSON deserializer fails on it. Not only that, any deployments created using the current Octokit.net will create an invalid payload. This PR fixes it by changing the type of `Payload` to a dictionary. THIS IS A BREAKING CHANGE, but the old behavior was broken so it forces a new correct behavior. Fixes octokit#2250
When serializing the `NewDeployment` type, the `Payload` is serialized as an escaped string because JSON.NET doesn't know it's meant to be JSON. This causes a problem when you call the API because the Payload is supposed to be a JSON dictionary that's just part of the overall payload. It's not supposed to be an escaped string. That's why the JSON deserializer fails on it. Not only that, any deployments created using the current Octokit.net will create an invalid payload. This PR fixes it by changing the type of `Payload` to a dictionary. THIS IS A BREAKING CHANGE, but the old behavior was broken so it forces a new correct behavior. Fixes octokit#2250
When serializing the `NewDeployment` type, the `Payload` is serialized as an escaped string because JSON.NET doesn't know it's meant to be JSON. This causes a problem when you call the API because the Payload is supposed to be a JSON dictionary that's just part of the overall payload. It's not supposed to be an escaped string. That's why the JSON deserializer fails on it. Not only that, any deployments created using the current Octokit.net will create an invalid payload. This PR fixes it by changing the type of `Payload` to a dictionary. THIS IS A BREAKING CHANGE, but the old behavior was broken so it forces a new correct behavior. Fixes octokit#2250
When serializing the `NewDeployment` type, the `Payload` is serialized as an escaped string because JSON.NET doesn't know it's meant to be JSON. This causes a problem when you call the API because the Payload is supposed to be a JSON dictionary that's just part of the overall payload. It's not supposed to be an escaped string. That's why the JSON deserializer fails on it. Not only that, any deployments created using the current Octokit.net will create an invalid payload. This PR fixes it by changing the type of `Payload` to a dictionary. THIS IS A BREAKING CHANGE, but the old behavior was broken so it forces a new correct behavior. Fixes #2250
As per the documentation the
deployment.payload
is intended to accept json.Octokit.net has
NewDeployment.Payload
as string.When creating a new deployment with a json serialized string in
Payload
the request is accepted and the deployment is created. However, it fails with anInvalidCastException
when attempting return theDeployment
response model.On closer inspection it appears to be an issue with the Deployment response model expecting to be able to cast to a
IReadOnlyDictionary<string,string>
yet the NewDeployment request model accepts a string.See https://github.com/octokit/octokit.net/blob/main/Octokit/Models/Response/Deployment.cs#L60
and https://github.com/octokit/octokit.net/blob/main/Octokit/Models/Request/NewDeployment.cs#L62
Here is some of my sandbox code I used that raised the error.
This is using Octokit 0.48.0
I get the following error
Of note, i also tried creating a NewDeployment serializing a
Dictionary<string,string>
to payload but got the same result. Deployment was created on github but Octokit failed with a cast exception.When calling github directly via curl I can see my deployment object created as expected. Note payload is a string and not json.
Is this a bug or am i over thinking it?
The text was updated successfully, but these errors were encountered: