MNT Fix link test to not pre-cache link owner before test starts.#392
Merged
emteknetnz merged 1 commit intosilverstripe:5from Jul 2, 2025
Merged
Conversation
With the new caching, this will fail tests that add versioned to the class. That's because of a combination of factors: - extension instances are stored on instances instead of accessed statically - in `DataObject::get_one()`, the `getUniqueKeyComponents()` method is used to determine the cache key, which just _happens_ to be called on a singleton, and we just _happen_ to have not generated a singleton of the class until now, which means it has the versioned extension freshly added to it. This would be extremely unlikely to occur in real code, and I think our response to a bug report would be "reset your cache after applying the extension, or just don't fiddle around with extensions at runtime except inside `_config.php`".
emteknetnz
approved these changes
Jul 2, 2025
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.
With the new caching, this will fail tests that add versioned to the class. That's because of a combination of factors:
DataObject::get_one(), thegetUniqueKeyComponents()method is used to determine the cache key, which just happens to be called on a singleton, and we just happen to have not generated a singleton of the class until now, which means it has the versioned extension freshly added to it and that is counted in the cache key where before that part of the cache key was empty (and therefore the key doesn't match the original unversioned record's cache key withget_one)DataListwhen caching is enabled,getUniqueKeyComponents()isn't taken into account - instead the resulting SQL is used. This includes versioning (see new tests in MNT Test new cache doesn't bleed across stages silverstripe-versioned#517) but the versioned state is draft which uses the base table, so the SQL matches the original query and returns the originally cached record (which is correct behaviour).This would be extremely unlikely to occur in non-test code, and I think our response to a bug report would be "reset your cache after applying the extension, or just don't fiddle around with extensions at runtime except inside
_config.php".Important
Relies on silverstripe/silverstripe-framework#11768
DO NOT MERGE until that PR has been merged in
Issue
DataListsilverstripe-framework#11767