BUG Fix DataObject / Versioned publishing issues #2917
Merged
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.
This issue was initially raised at and fixes silverstripe/silverstripe-blog#105.
After investigation I found the following issues.
If a DataObject was queried under a certain stage or reading mode, and then this mode changes, lazy-loading of fields would fail since it will always attempt to use the current mode. This is fixed in
DataObject::loadLazyFields
so that anyDataObject
will maintain it's own query parameters internally, propegating this context from initial load all the way to lazy loading of fields.This fix was made in
DataObject
rather than inVersioned::augmentLoadLazyFields
because (in my humble opinion) it's the role of the DataObject to maintain its own query context, and it should only be touched by extensions to modify this explicitly. This is easier than updating each dataobject extension across the board.Secondly,
Versioned::writeToStage
was failing if no fields were modified, meaning simply loading a record from one stage and writing it to another would result in no write performed.Test cases were included in
VersionedTest
rather thanDataObjectLazyLoadingTest
becuase I feel that this is more a test of the Versioned extension (and DataObject's support for extensions) than the lazy loading process itself. I could just as easy have put it there though. :)I've marked this as "don't merge" because I'd like to get a few developer opinions before I'm confident this is the correct solution.