fix: move timezone string creation before startTimestamp to avoid nesting assertion#148
Merged
Merged
Conversation
…ting assertion FlatBuffers' `create(string:)` calls `notNested()` which asserts `!isNested`. In the `.timestamp` case of `toFBType()`, the timezone string was created inside the `startTimestamp`/`endTimestamp` table context, which has `isNested = true`. This causes a runtime assertion failure when writing any schema with `Timestamp` that has a timezone (e.g. `timestamp[us, UTC]`). The fix moves `fbb.create(string:)` before `startTimestamp()`, which is the standard FlatBuffers pattern: all child objects (strings, vectors, tables) must be created before starting their parent table. Made-with: Cursor
e8af1c0 to
3923641
Compare
Member
|
Could you also add a new test for the case? |
Member
|
Could you read https://arrow.apache.org/docs/dev/developers/overview.html#ai-generated-code carefully? |
Contributor
Author
|
Thanks for the review. I've pushed a test (testTimestampWithTimezoneInMemoryToFromStream) that does a write/read roundtrip with a timestamp[us, UTC] column. This exercises the exact code path that crashed before the fix. I've read the AI policy. The fix and test were written with AI assistance (Cursor). I identified the issue when try to use this package. AI helped root cause by tracing FlatBuffers' startTable -> isNested = true -> create(string:) -> notNested() assertion chain, and I've reviewed and verified all generated code. I understand the fix and can debug it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ArrowWriter.writeStreaming()crashes with a FlatBuffers assertion when writing any schema containing aTimestampfield with a timezone (e.g.timestamp[us, UTC]):In
toFBType()(ArrowWriterHelper.swift), the.timestampcase callsfbb.create(string: timezone)inside thestartTimestamp/endTimestamptable context. FlatBuffers'create(string:)callsnotNested()which asserts!isNested, butstartTimestamp(which callsstartTable) has already setisNested = true.Fix
Move the
fbb.create(string:)call beforestartTimestamp(). This is the standard FlatBuffers pattern: all child objects (strings, vectors, tables) must be created before starting their parent table.Testing
Added
testTimestampWithTimezoneInMemoryToFromStreamwhich writes atimestamp[us, UTC]column throughwriteStreamingand reads it back, verifying the schema (unit, timezone) and data survive the roundtrip. This test would crash with the nesting assertion before the fix.AI disclosure
The code change and test were written with the assistance of Cursor (AI). I identified the bug by tracing the FlatBuffers assertion through the startTable/notNested call chain, reviewed all generated code, and verified correctness by running the test suite locally.