Problem/Motivation

In ContentEntityStorageBase::doSave():

    // @todo Consider returning a different value when saving a non-default
    //   entity revision. See https://www.drupal.org/node/2509360.
    $return = $entity->isDefaultRevision() ? SAVED_UPDATED : FALSE;

Proposed resolution

TBD

Remaining tasks

TBD

User interface changes

None

API changes

TBD

Data model changes

None

Issue fork drupal-2509360

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

plach’s picture

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

apaderno’s picture

Version: 8.9.x-dev » 9.4.x-dev
apaderno’s picture

Issue summary: View changes

FALSE is documented to be returned when saving the entity failed. That is the wrong value to return, as the entity could have been successfully saved.

dpi’s picture

Hit this myself after adding return type int to a save method on a revisionable entity. Which means that the interface is documented incorrectly at \Drupal\Core\Entity\EntityInterface::save as accepting only returning int. But it is in fact int|FALSE.

What exactly is the reason \Drupal\Core\Entity\ContentEntityStorageBase::doSave returns FALSE? Surely the FALSE it is still success, so why falsey?

Also has another cascading effect in that it breaks typed \Drupal\Core\Entity\EntityFormInterface::save implementors.

dpi’s picture

Status: Active » Needs review

Well, tests pass. So thats great I guess, so nothing in core seems to be relying on this, or tests it.

Putting it up for review/discussion.

mmbk’s picture

Status: Needs review » Reviewed & tested by the community

This solves the problem with some failing tests in https://www.drupal.org/project/drupal/issues/3264370

The failures where introduced after fixing Drupal\Node\NodeForm::save()

alexpott’s picture

Category: Task » Bug report
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

Obviously we don't have test coverage if this very very odd behaviour because no tests have failed. I think this is telling us we should add a test. I also think that this is a bug because returning FALSE when something has been saved is very odd.

larowlan’s picture

Should we add an extra constant here? We could use bitwise operators.

if ($entity->save() & SAVED_UPDATED_NON_DEFAULT)) {
}
Berdir’s picture

FWIW, I never liked those return values in the first place and think we should consider to deprecate having a return value entirely if that's feasible to do.

\Drupal\node\NodeForm::save() shows that it's pretty easy to get this information yourself, just call $entity->isNew() before saving. Same for the default revision. (It also still has bogus code that checks if the node has an id, which hasn't worked like that since Drupal 6, we have separate issues about catching exceptions instead).

Not sure if the DX of that isn't actually better than these constants (which are also on the list of constants to move from include fields and might need some change anyway).

mmbk’s picture

Hmm, I think having no return value for a 'save' function at all, is not a good idea, as a developer I want to know whether an entity was saved successfully without having to catch exceptions, but returning a boolean would be fine. The additional information whether the record is new, or is a draft revision could/should retrieved by other means.

Changes of the return value will affect probably all EntitySave and FormSave methods 2525794

Concerning the actual code, imho it is definitely wrong to return FALSE, when the record was actually saved successfully.

Berdir’s picture

> Hmm, I think having no return value for a 'save' function at all, is not a good idea, as a developer I want to know whether an entity was saved successfully without having to catch exceptions

That ship has sailed about 10 years ago :)

There is no "saving failed" return value, a failure means an exception. A try/catch is the only correct approach to check if saving worked and to prevent a failure from bubbling up and interrupting everything. And yes, core and specifically entity forms are doing a very bad job at that.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

acbramley’s picture

Just hit this in the exact same way as #12

kim.pepper’s picture