Conversation
|
I am making serialization stricter here. @NuGet/nuget-client Similar question to all of you. Any concerns with the "risky decisions" here? |
It's definitely possible. I recommend asking your agent to compare these client-side model changes with the associated server side code (not models, these are not null annotated. |
I believe it's possible at least one 3rd party server implementation will not have read the docs, but would have just tried to run a restore, see where NuGet failed, update their implementation, and repeat until restore passed. So, anything the docs say must be non null, but isn't enforced by client, I think is likely to be null in at least one server implementation. I haven't yet looked at this PR, but my question is how it's handled. If we're annotating it as not null, but not changing the deserializer to enforce it, then we'll end up with NRE crashes on types we've marked as not null, which might make it more difficult to investigate. If we change the deserializer to start enforcing not null on something that wasn't previously enforced, we'll break customers. My gut feeling is that we should probably mark all our deserialization class properties as nullable, and we'll just have to deal with it in all our code. Maybe another approach is start enforcing not null in deserialization, but add a NUGET_UNSUPPORTED_ALLOW_PROTOCOL_ERRORS environment variable for customers to opt out, until they can migrate to a different server implementation that isn't broken. If a future version of NuGet starts throwing NRE and customers complain, we can say that the environment variable calls out that it's unsupported. This idea would need to be validated with the breaking change process. |
@joelverhagen I'll try that. I had it rely on the documentation. I don't know how succesfull it'll be at looking at the server impl.
I guess I'd need to dig deeper there to see whether these types having null would break client. That changes the bar.
The changes here change the deserializer.
I genuinely think this will make the nullability gains disappear, because we're gonna be suppressing nullability warnings in so many places. We can chat offline. I think there's something to gating changes behind env var. I'll think about it. |
|
Looking at the 3 types:
Thoughts? |
|
OK, implemented all those changes + updated description. PTAL. |
Phase 1: Constants, interfaces, exceptions, events, validated models Phase 2: JSON models, search types, converters Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- PackageDeprecationMetadata.Reasons: replace Required.Always + null! with Array.Empty<string>() default — safer for 3rd party servers - Fix CS8600 in PackageSearchResultTableRenderer: Message is now string? Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
3rd party servers may omit this field. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
d6ddda9 to
398cef3
Compare
Progress on: NuGet/Home#14851
Description
Remove
#nullable disablefrom 24 leaf-type files inNuGet.Protocol. Most changes are mechanical — the interesting decisions are below.Significant decisions
JSON model nullability driven by NuGet V3 protocol spec:
AlternatePackageMetadataPackageIdstring?AlternatePackageMetadataRangeVersionRange?PackageDeprecationMetadataReasonsArray.Empty<string>()defaultPackageDeprecationMetadataMessagestring?PackageDeprecationMetadataAlternatePackageAlternatePackageMetadata?RepositoryCertificateInfo— all fieldsRequired.Alwaysper repo signatures spec. Risk is minimal since this is package signing infrastructure declared in one place on nuget.org, andIRepositoryCertificateInfois already declared in NuGet.Packaging.PackageProgressEventArgs.PackageSource→PackageSource?— constructor accepts null,HasPackageSourcechecks for it. Also marked[Obsolete]since it has zero usages in the codebase.VersionInfo.PackageSearchMetadata→IPackageSearchMetadata?— XML doc explicitly states it's null for V3 sources.VersionRangeConverter.WriteJson— explicitArgumentNullExceptionguard instead of!-suppression on the nullablevalueparameter.Downstream fix
PackageSearchResultTableRenderer.cs—PackageDeprecationMetadata.Messageis nowstring?, added?? "N/A"fallback.Mechanical changes
Everything else is removal of
#nullable disablefrom types where all members are provably non-null: constants, exception hierarchies, event types with constructor-set properties, and models with constructor validation. 65 oblivious (~) entries updated inPublicAPI.Shipped.txtfor both TFMs.PR Checklist