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

Plugin setAttributes error due to getting/setting of settings behaviour #4706

Closed
joshuabaker opened this issue Aug 5, 2019 · 3 comments
Closed

Comments

@joshuabaker
Copy link
Contributor

Description

Plugin::setSettings is called where a plugin is initiated, however, the default behaviour is to call Plugin::getSettings, which can return null. This results in exceptions for plugins that do not have settings.

Error: Call to a member function setAttributes() on null

Reference

cms/src/base/Plugin.php

Lines 195 to 206 in 1239460

public function getSettings()
{
if ($this->_settingsModel === null) {
$this->_settingsModel = $this->createSettingsModel() ?: false;
}
if ($this->_settingsModel !== false) {
return $this->_settingsModel;
}
return null;
}

cms/src/base/Plugin.php

Lines 211 to 214 in 1239460

public function setSettings(array $settings)
{
$this->getSettings()->setAttributes($settings, false);
}

@joshuabaker
Copy link
Contributor Author

Related issue: craftcms/postmark#10

@brandonkelly
Copy link
Member

This looks like a Postmark bug so I’ll fix it over there, but in the meantime you should be able to fix this locally by clearing out your settings column value for the postmark plugin in your plugins table.

@brandonkelly
Copy link
Member

brandonkelly commented Aug 7, 2019

While this was really a Postmark bug, it turns out that there’s no way for the plugin to actually fix the underlying issue without an update on Craft’s end to be more graceful if setSettings() is called for a plugin without settings. So I ended up implementing a fix similar to #4707 for the next Craft release.

To get the fix early, change your craftcms/cms requirement in composer.json to:

"require": {
  "craftcms/cms": "dev-develop#36ed8fa14d27670a5ff7293886ffa8ccff5cc5e7 as 3.2.9",
  "...": "..."
}

Then run composer update.

Once you’ve done that, you should update to Postmark 2.0.2, which fixes the underlying issue. Until you do, Craft will start logging warnings to storage/logs/web.log on every request.

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 a pull request may close this issue.

2 participants