-
Notifications
You must be signed in to change notification settings - Fork 52
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
Ensure both arguments passed to merge_settings
are an array
#733
Conversation
…aved setting isn't. In those scenarios, not only should we not run the merge_settings method again but let's use our default setting since the saved setting is incorrect
I believe I've finally figured out proper reproduction steps here. The ones outlined in the PR description still work (manually changing data) but I'm pretty sure I've figured out that actual use case. In #374, we changed how the descriptive text generator feature works. Previously it was either on or off and if on, it would save the text in the But this also means the settings we saved changed from being a So to reproduce:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM and tests well.
Description of the Change
We have a
merge_settings
method that takes in stored settings as well as the default settings and merges those together. This method expects both of these values to be anarray
, so if non-array data is passed in, a PHP error occurs.This method is called recursively to merge settings that contain array data. This was throwing a fatal error in #732 because the passed in settings were not an array but the default settings were.
This PR adds additional checks here to ensure we only ever call
merge_settings
if both the stored settings and default settings are an array. For instances were the stored settings aren't an array but the defaults are, we override the stored settings with the defaults as it seems the only time this happens is when data has been stored improperly (or not migrated properly in v3.0.0).In addition, some followup in #732 pointed to some additional issues in the descriptive text generator feature where it expects array data but is instead passed in non-array data. In theory this should never happen but again, in scenarios where data is stored improperly or migrated wrong, I've added additional checks to avoid PHP errors and warnings.
Closes #732
How to test the Change
There are good details in #732 but I've not been able to replicate the problem yet without manually manipulating data.
Here's the steps I followed:
classifai_feature_descriptive_text_generator
option in the database. Change thedescriptive_text_fields
item to be the value1
instead of an arrayChangelog Entry
Credits
Props @ajaxthemestudios, @dkotter
Checklist: