Skip to content

Fix lazy field handling in base class and OrFail templates#91

Merged
dereuromark merged 4 commits intomasterfrom
fix/lazy-base-class-and-orfail
Mar 23, 2026
Merged

Fix lazy field handling in base class and OrFail templates#91
dereuromark merged 4 commits intomasterfrom
fix/lazy-base-class-and-orfail

Conversation

@dereuromark
Copy link
Copy Markdown
Contributor

@dereuromark dereuromark commented Mar 23, 2026

Summary

Comprehensive lazy field handling fixes discovered in deep dive.

Base class fixes (Dto.php):

  • Fix base validate() to check _lazyData for required lazy fields
  • Fix base setDefaults() to not overwrite lazy field data

Template fixes:

  • Fix setDefaults template to check _lazyData for lazy fields with defaults
  • Fix method_get_or_fail.twig to call getter (handles lazy hydration)
  • Fix method_set_or_fail.twig to clear _lazyData for lazy fields
  • Fix method_with_or_fail.twig to clear _lazyData for lazy fields
  • Fix method_add.twig to hydrate lazy collection before adding (prevents data loss)
  • Fix method_remove.twig to hydrate lazy collection before removing
  • Fix method_with_added.twig to hydrate lazy collection before adding
  • Fix method_with_removed.twig to hydrate lazy collection before removing

Tests:

  • Add 11 code generation tests verifying lazy field handling in templates
  • Add lazy-specific performance benchmark

Relates to #83

- Fix base validate() to check _lazyData for required lazy fields
- Fix base setDefaults() to not overwrite lazy field data
- Fix setDefaults template to check _lazyData for lazy fields with defaults
- Fix method_get_or_fail.twig to call getter (handles hydration)
- Fix method_set_or_fail.twig to clear _lazyData for lazy fields
- Fix method_with_or_fail.twig to clear _lazyData for lazy fields
Tests verify that generated code properly handles lazy fields:
- setFromArrayFast uses array_key_exists
- setDefaults checks _lazyData for lazy fields with defaults
- validate checks _lazyData for required lazy fields
- getOrFail calls getter (handles hydration)
- setOrFail clears _lazyData
- withOrFail clears _lazyData
- getter uses array_key_exists for null detection
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.48%. Comparing base (2bc0c90) to head (8de06cc).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##             master      #91   +/-   ##
=========================================
  Coverage     83.48%   83.48%           
- Complexity     1388     1390    +2     
=========================================
  Files            40       40           
  Lines          3348     3348           
=========================================
  Hits           2795     2795           
  Misses          553      553           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

The add/remove methods for lazy collections were clearing _lazyData
before hydration, causing existing collection items to be lost.

Fixed by calling the getter first (which handles hydration and clears
_lazyData internally) before modifying the collection.

Affected templates:
- method_add.twig
- method_remove.twig
- method_with_added.twig
- method_with_removed.twig

Added tests to verify the fix and a lazy-specific benchmark.
@dereuromark dereuromark merged commit a2d317e into master Mar 23, 2026
10 checks passed
@dereuromark dereuromark deleted the fix/lazy-base-class-and-orfail branch March 23, 2026 03:17
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