Skip to content

Write the weight index as the physical 8-byte slot (3.2.1) - #33

Merged
TonisOrmisson merged 2 commits into
masterfrom
fix/weight-oct-slot
Dec 1, 2026
Merged

TonisOrmisson merged 2 commits into
masterfrom
fix/weight-oct-slot

Conversation

@TonisOrmisson

@TonisOrmisson TonisOrmisson commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Writer::writeDataset() took header weightIndex from VariableMetadata::$dictionaryIndex or the logical position. SPSS expects the 1-based 8-byte slot, so a weight placed after a string wider than 8 bytes was lost on reading. The writer now counts slots (Utils::widthToOcts for strings) from the written dictionary.

Tests: a 20-byte string, a number and a 300-byte very long string before the weight with a stale dictionaryIndex (slot 43), and a weight variable missing from the dictionary.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected weight-variable placement when writing datasets containing string fields, preventing the weight from being assigned to the wrong slot.

@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The writer now calculates the weight variable’s slot from the written dictionary, counting string-variable slots by octet width. Tests cover the calculated index in a typed dataset round-trip and the error raised when the weight variable is absent. The changelog records the fix.

Changes: Weight index calculation

Layer / File(s) Summary
Calculate and verify the weight slot
src/Sav/Writer.php, tests/DatasetRoundTripTest.php, CHANGELOG.md
The writer counts dictionary slots to locate the weight variable. Tests verify the round-trip index and the missing-variable error. The changelog records the fix and states that there are no runtime API changes.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: Minimal · up to e5e38

This fixes the weight index written for datasets with wide string variables before the weight variable. No outstanding merge-blocking risk is identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: the writer now emits the weight index as the 1-based physical 8-byte slot, counted from the written dictionary. The changelog, Writer.php summary, and PR objectives al…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: the writer now emits the weight index as the 1-based physical 8-byte slot, counted from the written dictionary. The changelog, Writer.php summary, and PR objectives all describe this same fix. The title is specific and concise, and it does not use vague terms. The '(3.2.1)' version tag is extra detail but does not make the title misleading.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: eeeaf0f1-ff74-4f3d-a1c2-44366f65d82a
Commits

Reviewing files that changed from the base of the PR and between a8a6d74 and e5e3889.

Files selected for processing: 3

  • CHANGELOG.md
  • src/Sav/Writer.php
  • tests/DatasetRoundTripTest.php

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@TonisOrmisson
TonisOrmisson merged commit 19fed38 into master Dec 1, 2026
15 checks passed
@TonisOrmisson
TonisOrmisson deleted the fix/weight-oct-slot branch December 1, 2026 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant