Using Drupal 8.5.1 and latest dev version of Workflow. Successfully set up a workflow with access and tranasitions via the UI. Successfully added Workflow fields to Content Types. Successfully transitioned Content with Workflow fields in Content Type.

Issue: Exported Configuration via the UI. When attempting import using:

drush cim --partial --no-halt-on-error --source=../config/sync -y

I get the following error:

Argument 1 passed to Drupal\workflow\Entity\WorkflowConfigTransition::setWorkflow() must be an instance of Drupal\workflow\Entity\Workflow, null given, called in [error]
.../docroot/modules/contrib/workflow/src/Entity/WorkflowConfigTransition.php on line 72 and defined WorkflowTypeAttributeTrait.php:37

Fatal error: Call to a member function id() on null in .../docroot/modules/contrib/workflow/src/WorkflowTypeAttributeTrait.php on line 38
Drush command terminated abnormally due to an unrecoverable error.

Configuration files attached.

CommentFileSizeAuthor
#15 interdiff_12-15.txt683 bytesankit agrawal
#15 workflow-config-transition-2961558-15.patch2.05 KBankit agrawal
#12 interdiff_10-12.txt695 bytesbalazswmann
#12 workflow-fix-config-deps-2961558-12-D8.patch1.56 KBbalazswmann
#10 workflow-fix-config-deps-2961558-10-D8.patch1.32 KBbalazswmann
workflow.transition.content_review_under_review_reviewed_approved.yml419 bytessassafrass
workflow.transition.content_review_under_review_under_review.yml244 bytessassafrass
workflow.workflow.content_review.yml267 bytessassafrass
workflow.transition.content_review_under_review_draft.yml395 bytessassafrass
workflow_access.settings.yml102 bytessassafrass
workflow_access.role_.yml1.46 KBsassafrass
workflow.transition.content_review_reviewed_approved_under_review.yml397 bytessassafrass
workflow.transition.content_review_reviewed_approved_reviewed_approved.yml264 bytessassafrass
workflow.transition.content_review_reviewed_approved_draft.yml383 bytessassafrass
workflow.transition.content_review_draft_under_review.yml373 bytessassafrass
workflow.transition.content_review_draft_reviewed_approved.yml383 bytessassafrass
workflow.transition.content_review_draft_draft.yml216 bytessassafrass
workflow.transition.content_review_creation_under_review.yml379 bytessassafrass
workflow.transition.content_review_creation_reviewed_approved.yml389 bytessassafrass
workflow.transition.content_review_creation_draft.yml377 bytessassafrass
workflow.state_.content_review_under_review.yml195 bytessassafrass
workflow.state_.content_review_reviewed_approved.yml207 bytessassafrass
workflow.state_.content_review_draft.yml179 bytessassafrass
workflow.state_.content_review_creation.yml186 bytessassafrass
workflow.settings.yml103 bytessassafrass

Comments

sassafrass created an issue. See original summary.

johnv’s picture

Is it possible that the yml files are parsed in the wrong order?
It should be : first workflow, then workflow.state , then workflow.transition.

In any case, I see that the values for 'label' and 'module' are noeer filled. I am not sure if this is an error.

sassafrass’s picture

Hi...and thank-you for the quick response.

I am not sure what order the files are being parsed in since it is controlled by the drush command. Is there a way to control the order other than doing one file import at a time?

johnv’s picture

I don't know. I'll try and import one by one.

  • johnv committed e101cb6 on 8.x-1.x
    Issue #2961558 by sassafrass: WorkflowConfigTransition::setWorkflow
    
johnv’s picture

Please try latest dev version.

estoyausente’s picture

Same error here with the latest version (that include this commit). I not sure the problem but the code doesn't seem to resolve it. I'm doing the import using drush.

I'm not sure how can help you to resolve, if I can do something just let me know.

estoyausente’s picture

I was debuggin and in the WorkflowConfigTransition.php constructor class, the $state cannot find the associated Workflow.

  public function __construct(array $values = [], $entityType = NULL) {
    // Please be aware that $entity_type and $entityType are different things!
    parent::__construct($values, $entity_type = 'workflow_config_transition');
    $state = WorkflowState::load($this->to_sid ? $this->to_sid : $this->from_sid);
    if($state) {
      $this->setWorkflow($state->getWorkflow()); // <--- THIS  $state->getWorkflow() return NULL and throw the error.
    }
  }

Your change doesn't resolve the problem because the setWorkflow method needs a Workflow Class as a input param and NULL is not a valid input. Furthermore, with the new change we are trying to do Null->wid = '' and it will throw an error too. I think that the problem is in the call.

I tested something like this:

  /**
   * {@inheritdoc}
   */
  public function __construct(array $values = [], $entityType = NULL) {
    // Please be aware that $entity_type and $entityType are different things!
    parent::__construct($values, $entity_type = 'workflow_config_transition');
    $state = WorkflowState::load($this->to_sid ? $this->to_sid : $this->from_sid);
    $workflowState = $state->getWorkflow();
    if($workflowState) {
      $this->setWorkflow($workflowState);
    }
  }

but it doesn't work. The import finish correctly but the states aren't be created successfully. I don't know where is the deep problem, I'm not sure how the Import process works :S

balazswmann’s picture

I can confirm this bug. Saving settings on the UI works well, but the configuration import fails.

balazswmann’s picture

The problem was that config dependencies were not defined for WorkflowState and WorkflowConfigTransition entities. The attached patch solves this problem.

balazswmann’s picture

Status: Active » Needs review
balazswmann’s picture

StatusFileSize
new1.56 KB
new695 bytes

The previous patch causes an infinite loop at the WorkflowState entity. Fixed patch attached.

ankit agrawal’s picture

@balazswmann Thank you for sharing the patch. I tried the above patch, and re-exported the configuration after saving the workflow form again, however still getting the following error on site-rebuild:

TypeError: Argument 1 passed to Drupal\workflow\Entity\WorkflowConfigTransition::setWorkflow() must be an instance of Drupal\workflow\Entity\Workflow, null given, called in modules/contrib/workflow/src/Entity/WorkflowConfigTransition.php on line 79 in modules/contrib/workflow/src/WorkflowTypeAttributeTrait.php on line 37 #0 modules/contrib/workflow/src/Entity/WorkflowConfigTransition.php(79): Drupal\workflow\Entity\WorkflowConfigTransition->setWorkflow(NULL)

ankit agrawal’s picture

Status: Needs review » Needs work
ankit agrawal’s picture

StatusFileSize
new2.05 KB
new683 bytes

Re-rolled the patch with updated changes:

ankit agrawal’s picture

Status: Needs work » Needs review
johnv’s picture

Title: WorkflowConfigTransition::setWorkflow » WorkflowConfigTransition::setWorkflow error when importing config

  • johnv committed fd5fc44 on 8.x-1.x authored by Ankit Agrawal
    Issue #2961558 by balazswmann, Ankit Agrawal, sassafrass, johnv:...
johnv’s picture

Version: 8.x-1.x-dev » 8.x-1.1
Status: Needs review » Fixed

Please try latest dev version.
- The symptom (Workflow = NULL) is removed by changing function setWorkflow(Workflow $workflow = NULL);
- The root cause is tackled by adding function calculateDependencies();
Thanks so far, hope this version works.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

laurent.lacote’s picture

Hi all ;)

First off, thanks to all maintainers for this module!
I find it really much better than its counterpart that was integrated to core, notably for the very lax coupling with revisioning system, the ability to stack several workflows on a same content and the ability to make workflow transitions independantly from node access. :)

I have however to be the bearer of bad news: the current bug still exists, and hard.
Steps to reproduce.
1. Activate module in 1.1 version (workflow + workflow UI, no need to activate Access).
2. Create one basic workflow with at least two states and one transition.
3. Try to export one configuration in UI (either single export or full archive): in all configuration yml files, the key "dependencies" stays empty at the very least for transitions configurations (from memory also true for state configuration but away from my work computer right now):
"dependencies: {}".

Whereas in my comprehension dependencies should follow this chain.
Module <- workflow <- state(s) -< transition.

Unfortunately, I currently have no idea how to help analyse the cause. This uses up many Drupal and POO concepts I'm not (yet) familiarized (enough) with.
My comprehension so far is that the problem may come from inside the calculateDependencies, either from the private methods getFromState and similar or the getDependencyConfigName, since the problem persists although those were added and supposed to fix it.

While I'm far from being an expert in development, I'll be happy to help troubleshooting this as long as you give me some direction in which to look for.

Thanks in advance!

Best regards,

Laurent Lacôte

johnv’s picture

Please use dev version. The error occurs in 1.1, and is fixed in the upcoming 1.2 release.

benjaminbradley’s picture

Hi, can we get a new release of this module please? This issue has been fixed for a year but there's no new release yet.

johnv’s picture

Title: WorkflowConfigTransition::setWorkflow error when importing config » TypeError in WorkflowConfigTransition::setWorkflow when importing config