Skip to content

fix(bindings/go,dotnet)!: preserve explicit empty string options - #9575

Merged
Xuanwo merged 2 commits into
mainfrom
xuanwo/preserve-optional-string-states
Dec 3, 2026
Merged

Xuanwo merged 2 commits into
mainfrom
xuanwo/preserve-optional-string-states

Conversation

@Xuanwo

@Xuanwo Xuanwo commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Which issue does this PR close?

Closes #9555.

Rationale for this change

Passing an empty IfMatch in Go or .NET could drop the precondition and let a write overwrite existing data. In .NET it could also let a delete remove the object.

What changes are included in this PR?

The Go generator records whether a caller supplied each string option and passes explicit strings through the existing C setters, keeping borrowed bytes alive through the operation. The .NET options writer uses one UTF-8 encoder that maps null to a null pointer and writes a terminator for an empty string. The .NET generator uses the same encoder for metadata and documents the distinction on the generated option properties. Generator review by Chitral Verma

The memory tests confirm that empty and nonempty ETag preconditions on an unsupported operation return Unsupported and preserve the stored bytes. The .NET ContentType test also reads back the three string states through Stat.

Are there any user-facing changes?

An explicit empty string now reaches OpenDAL as an option value. It goes through the same capability checks as other supplied values.

Breaking changes

Affected packages: bindings/go, bindings/dotnet

Migration:

  • In Go, omit the functional option when you want the default. If you build an option list from an optional ETag, append WriteWithIfMatch(etag) only when the caller supplied an ETag. WriteWithIfMatch("") now requests a conditional write.
  • In .NET, leave optional string properties unset or assign null to omit them. Convert empty placeholders to null where they represented missing values.

AI Usage Statement

  • Harness: Pi via T3 Code. Model: magpie/codex/gpt-6.2-astra. Effort: thinking=high. Role: Traced option forwarding, checked the C ABI boundary, and designed the regression coverage.
  • Harness: Pi via T3 Code. Model: magpie/codex/gpt-6.2-sol. Effort: thinking=max. Role: Implemented the fix, reproduced the regression on matching native builds, and verified the bindings and generator.
  • Harness: Pi via T3 Code. Model: magpie/codex/gpt-6.2-sol. Effort: thinking=high. Role: Independently reviewed the binding change and verified public API regressions against matching native builds.

@chitralverma chitralverma left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review of head e578dd6c7.

Blocking

  1. OpenDALMetadata.cs is generated. The generator still emits writer.Utf8(...) (dev/src/generate/dotnet.rs:450), and this PR deletes NativeOptionsWriter.Utf8. On the PR head, generate -l dotnet followed by cargo fmt changes all 8 lines back to writer.Utf8(...). So check_generated fails, and the next regeneration breaks the .NET build. Fix: emit writer.String(...) at dotnet.rs:450.

Non-blocking

  1. Empty ETag on services that support if_match. The new tests use memory and fs. Both reject if_match as Unsupported before any request. On S3, GCS and Azure Blob, the empty value reaches the request unchanged: OpWrite::check checks only if_match().is_some() (core/core/src/raw/ops.rs:1386), and s3_put_object_request, gcs_insert_object_xml_request and azblob_put_blob_request set an empty If-Match header. Some HTTP servers treat an empty If-Match as absent. Go's net/http checkIfMatch is one. I did not test a real storage service. If one ignores the empty header, WriteWithIfMatch("") still overwrites. Rust if_match("") reaches the same path, so a core follow-up can fix all bindings, for example by rejecting an empty ETag with ConfigInvalid.

  2. .NET API docs. The Go generator adds "An empty string is an explicit value. Omit this option to leave it unset." to each string option. The .NET XML docs, for example WriteOptions.IfMatch, do not state the null versus "" rule. Only the README does. options_cs.j2 renders only p.summary, so this needs a generator change.

Checked, no findings: generate -l c gives no diff. dev tests pass (199). In Go and .NET, an explicit "" reaches core as Some("").

This comment is AI assisted.

@chitralverma chitralverma left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

89556ba5a fixes findings 1 and 3. On this head, generate -l dotnet and generate -l c, followed by cargo fmt, give no diff. The dev tests pass (199). All 50 optional string properties in the .NET options classes now have the null versus "" remark.

Finding 2 (empty If-Match on services that support if_match) belongs in core and does not block this PR.

This comment is AI assisted.

@chitralverma

Copy link
Copy Markdown
Contributor

Follow-up for finding 2: core still sends if_match("") as an empty If-Match header on S3, GCS and Azure Blob, so rejecting an empty ETag in core with ConfigInvalid would close it for all bindings.

This comment is AI assisted.

@Xuanwo
Xuanwo merged commit 63966ac into main Dec 3, 2026
40 of 41 checks passed
@Xuanwo
Xuanwo deleted the xuanwo/preserve-optional-string-states branch December 3, 2026 10:07
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.

bug(bindings/dotnet,go): preserve explicit empty-string preconditions instead of dropping them into unconditional operations

3 participants