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

CreatedResult should accept null location #42576

Merged
merged 8 commits into from
Dec 8, 2022
Merged

Conversation

singh733
Copy link
Contributor

@singh733 singh733 commented Jul 5, 2022

Task #39454

CreatedResult should accept null location

Description
The primary resource created by the request is identified by either a Location header field in the response or, if no Location field is received, by the effective request URI.

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Jul 5, 2022
@ghost
Copy link

ghost commented Jul 5, 2022

Thanks for your PR, @singh733. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@Pilchie Pilchie added the area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels label Jul 5, 2022
Copy link
Member

@halter73 halter73 left a comment

Choose a reason for hiding this comment

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

Thanks @singh733! I'll try to get back to you soon with the API decision.

@@ -64,19 +60,10 @@ public CreatedResult(Uri location, object? value)
/// <summary>
/// Gets or sets the location at which the content has been created.
/// </summary>
public string Location
Copy link
Member

Choose a reason for hiding this comment

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

When approving the API in #39454 (comment), we did not consider that this property would need to be made nullable. I'll update the API proposal and see if everyone still thinks we should change MVC's CreatedResult or if it's too breaking.

We can work out the PublicAPI.Unshipped.txt changes to get the build to pass. It gets complicated when changing the nullability of shipped APIs. We might have to bypass the build check when changing the nullablity of a property setter like this.

Copy link
Member

Choose a reason for hiding this comment

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

To fix this you need to update the shipped.txt file for nullability changes instead of the unshipped.txt file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@BrennanConroy When we update the shipped.txt file we got the following error in build.

image

Copy link
Member

Choose a reason for hiding this comment

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

That's expected, someone will be able to override that and merge the PR

Copy link
Member

@halter73 halter73 left a comment

Choose a reason for hiding this comment

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

I think you're good once you delete TypedResults.Created(string uri) and TypedResults.Created(Uri uri). We can deal with the PublicAPI.Unshipped.txt changes like I mentioned earlier.

src/Http/Http.Results/src/TypedResults.cs Show resolved Hide resolved
@halter73
Copy link
Member

halter73 commented Jul 7, 2022

One more thing. There were also a bunch of Created() overloads in the approved API that this should add.

@captainsafia
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@captainsafia
Copy link
Member

captainsafia commented Dec 6, 2022

Triage: Need to follow-up on the PublicAPI.txt issues that are blocking this. Let's see about merging with override if there are no other issues in this PR.

@singh733
Copy link
Contributor Author

singh733 commented Dec 7, 2022

@captainsafia Do you need any change from my side ?

@halter73
Copy link
Member

halter73 commented Dec 8, 2022

@singh733 Thanks for offering to continue updating this after all this time! I appreciate you sticking with it.

I think I managed to massage the PublicAPI.Unshipped.txt files to get the build passing. I thought we were going to have to resort to changing a PublicAPI.Shipped.txt to get the nullability change to the Location property through, but it seems it's alright with claiming the setter is unchanged. Sometimes the analyzer doesn't capture enough information to notice API changes. See dotnet/roslyn-analyzers#3047 and dotnet/roslyn-analyzers#3901. While I was at it, I rebased your changes on main.

Because this didn't make it for .NET 7, I removed the changes that removed Created(string uri) and Created(Uri uri) from TypedResults now that it's shipped API.

I also reverted the change that caused Results to always return Created<object> even when given a null value like TypedResults do. I like always returning the same runtime type from a given method in principle, but now I don't think it's worth breaking code that might depend on the Results returning Created instead of Created<TValue> in the null value case. Hopefully code that cares about the runtime types of these things will use TypedResults instead.

@halter73 halter73 merged commit 74a2287 into dotnet:main Dec 8, 2022
@halter73
Copy link
Member

halter73 commented Dec 8, 2022

Thanks again @singh733!

@ghost ghost added this to the 8.0-preview1 milestone Dec 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants