Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX Respect explicit casting before casting arrays #11271

Merged

Conversation

GuySartorelli
Copy link
Member

@GuySartorelli GuySartorelli commented Jun 11, 2024

Fixes https://github.com/symbiote/silverstripe-multivaluefield/actions/runs/9358332818/job/25759951695

  1. Symbiote\MultiValueField\Tests\MultiValueFieldTest::testUpdate
    BadMethodCallException: Object->__call(): the method 'getValues' does not exist on 'SilverStripe\ORM\ArrayList'

This was caused by #11244 which didn't respect explicit pre-defined casting before casting arrays.

Needs silverstripe/silverstripe-cms#2960 for CI to be happy.

Issue

Comment on lines -391 to +392
public function castingHelper($field)
public function castingHelper($field, bool $useFallback = true)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opted to add an extra param here instead of just never including defaults from this method because this reduces upgrade pains - any usage of this method outside of the obj() method should always fall back on the default casting.

@@ -559,15 +581,25 @@ public function obj($fieldName, $arguments = [], $cache = false, $cacheName = nu
$value = $this->$fieldName;
}

// Try to cast object if we have an explicit cast set
if (!is_object($value)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping this condition here (mirroring the below) because if a method returns an explicit object (usually DBField), the implication is that it shouldn't be re-cast.

We could choose to change that, but if so it should be handled in a separate card with an issue for that purpose.

@emteknetnz emteknetnz merged commit b53cda8 into silverstripe:6 Jun 11, 2024
15 checks passed
@emteknetnz emteknetnz deleted the pulls/6/fix-casting-bug branch June 11, 2024 04:49
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.

2 participants