[Push Publishing] Cannot save Workflow Task of Contents pushed via Workflows
So far there are a few improvements and fixes that ContentHandler and our Content API require in order to fully process contents pushed via workflows.
So far, there are a couple of calls that are missing, and still this is causing an issue with Workflow Tasks.
Once a content is pushed, it should be saved in the DB, and after debugging in IntelliJ, we see the content being processed just fine by the Content API. However, once the ContentWorkflowHandler is called in order to save this content's Workflow Tasks, it fails because it cannot find the content that was recently saved.
[10/01/18 16:52:00:131 CST] INFO rest.PublishThread: Started bundle publish process
[10/01/18 16:52:00:578 CST] WARN util.JDBCExceptionReporter: SQL Error: 547, SQLState: 23000
[10/01/18 16:52:00:578 CST] ERROR util.JDBCExceptionReporter: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_workflow_task_asset". The conflict occurred in database "dotcmsreceiver", table "dbo.identifier", column 'id'.
[10/01/18 16:52:00:578 CST] ERROR impl.SessionImpl: Could not synchronize database state with session
[10/01/18 16:52:00:581 CST] ERROR business.PublisherAPIImpl: Error Publishing Bundle: Unable to flush Hibernate Session
com.dotcms.publishing.DotPublishingException: Unable to flush Hibernate Session
at com.dotcms.enterprise.publishing.remote.handler.ContentWorkflowHandler.handleContentWorkflow(ContentWorkflowHandler.java:143) ~[ee_clean.jar:?]
at com.dotcms.enterprise.publishing.remote.handler.ContentWorkflowHandler.handle(ContentWorkflowHandler.java:84) ~[ee_clean.jar:?]
at com.dotcms.publisher.receiver.BundlePublisher.process(BundlePublisher.java:206) [dotcms_4.2.2_999999.jar:?]
at com.dotcms.rest.PublishThread.run(PublishThread.java:42) [dotcms_4.2.2_999999.jar:?]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_121]
Caused by: com.dotmarketing.exception.DotHibernateException: Unable to flush Hibernate Session
at com.dotmarketing.db.HibernateUtil.saveWithPrimaryKey(HibernateUtil.java:1039) ~[dotcms_4.2.2_999999.jar:?]
at com.dotmarketing.portlets.workflows.business.WorkflowFactoryImpl.saveWorkflowTask(WorkflowFactoryImpl.java:1125) ~[dotcms_4.2.2_999999.jar:?]
at com.dotmarketing.portlets.workflows.business.WorkflowAPIImpl.saveWorkflowTask_aroundBody48(WorkflowAPIImpl.java:380) ~[dotcms_4.2.2_999999.jar:?]
at com.dotmarketing.portlets.workflows.business.WorkflowAPIImpl$AjcClosure49.run(WorkflowAPIImpl.java:1) ~[dotcms_4.2.2_999999.jar:?]
at org.aspectj.runtime.reflect.JoinPointImpl.proceed(JoinPointImpl.java:149) ~[aspectjrt-1.8.10.jar:?]
at com.dotcms.aspects.aspectj.AspectJDelegateMethodInvocation.proceed(AspectJDelegateMethodInvocation.java:43) ~[dotcms_4.2.2_999999.jar:?]
at com.dotmarketing.db.LocalTransaction.wrapReturnWithListeners(LocalTransaction.java:39) ~[dotcms_4.2.2_999999.jar:?]
at com.dotcms.aspects.interceptors.WrapInTransactionMethodInterceptor.invoke(WrapInTransactionMethodInterceptor.java:23) ~[dotcms_4.2.2_999999.jar:?]
at com.dotcms.aspects.aspectj.WrapInTransactionAspect.invoke(WrapInTransactionAspect.java:41) ~[dotcms_4.2.2_999999.jar:?]
at com.dotmarketing.portlets.workflows.business.WorkflowAPIImpl.saveWorkflowTask(WorkflowAPIImpl.java:379) ~[dotcms_4.2.2_999999.jar:?]
at com.dotcms.enterprise.publishing.remote.handler.ContentWorkflowHandler.handleContentWorkflow(ContentWorkflowHandler.java:131) ~[ee_clean.jar:?]
... 4 more
Caused by: com.dotcms.repackage.net.sf.hibernate.exception.ConstraintViolationException: could not insert: [com.dotmarketing.portlets.workflows.model.WorkflowTask#5c14ac43-7b19-44bf-9964-766bee353d7e]
at com.dotcms.repackage.net.sf.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:62) ~[dot.hibernate-2.1.7_2.jar:?]
at com.dotcms.repackage.net.sf.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29) ~[dot.hibernate-2.1.7_2.jar:?]
at com.dotcms.repackage.net.sf.hibernate.persister.AbstractEntityPersister.convert(AbstractEntityPersister.java:1331) ~[dot.hibernate-2.1.7_2.jar:?]
at com.dotcms.repackage.net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:472) ~[dot.hibernate-2.1.7_2.jar:?]
at com.dotcms.repackage.net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:436) ~[dot.hibernate-2.1.7_2.jar:?]
at com.dotcms.repackage.net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:37) ~[dot.hibernate-2.1.7_2.jar:?]
at com.dotcms.repackage.net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2449) ~[dot.hibernate-2.1.7_2.jar:?]
at com.dotcms.repackage.net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2435) ~[dot.hibernate-2.1.7_2.jar:?]
at com.dotcms.repackage.net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2392) ~[dot.hibernate-2.1.7_2.jar:?]
at com.dotcms.repackage.net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2261) ~[dot.hibernate-2.1.7_2.jar:?]
at com.dotmarketing.db.HibernateUtil.saveWithPrimaryKey(HibernateUtil.java:1037) ~[dotcms_4.2.2_999999.jar:?]
at com.dotmarketing.portlets.workflows.business.WorkflowFactoryImpl.saveWorkflowTask(WorkflowFactoryImpl.java:1125) ~[dotcms_4.2.2_999999.jar:?]
at com.dotmarketing.portlets.workflows.business.WorkflowAPIImpl.saveWorkflowTask_aroundBody48(WorkflowAPIImpl.java:380) ~[dotcms_4.2.2_999999.jar:?]
at com.dotmarketing.portlets.workflows.business.WorkflowAPIImpl$AjcClosure49.run(WorkflowAPIImpl.java:1) ~[dotcms_4.2.2_999999.jar:?]
at org.aspectj.runtime.reflect.JoinPointImpl.proceed(JoinPointImpl.java:149) ~[aspectjrt-1.8.10.jar:?]
at com.dotcms.aspects.aspectj.AspectJDelegateMethodInvocation.proceed(AspectJDelegateMethodInvocation.java:43) ~[dotcms_4.2.2_999999.jar:?]
at com.dotmarketing.db.LocalTransaction.wrapReturnWithListeners(LocalTransaction.java:39) ~[dotcms_4.2.2_999999.jar:?]
at com.dotcms.aspects.interceptors.WrapInTransactionMethodInterceptor.invoke(WrapInTransactionMethodInterceptor.java:23) ~[dotcms_4.2.2_999999.jar:?]
at com.dotcms.aspects.aspectj.WrapInTransactionAspect.invoke(WrapInTransactionAspect.java:41) ~[dotcms_4.2.2_999999.jar:?]
at com.dotmarketing.portlets.workflows.business.WorkflowAPIImpl.saveWorkflowTask(WorkflowAPIImpl.java:379) ~[dotcms_4.2.2_999999.jar:?]
at com.dotcms.enterprise.publishing.remote.handler.ContentWorkflowHandler.handleContentWorkflow(ContentWorkflowHandler.java:131) ~[ee_clean.jar:?]
... 4 more
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_workflow_task_asset". The conflict occurred in database "dotcmsreceiver", table "dbo.identifier", column 'id'.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:217) ~[sqljdbc42.jar:?]
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1635) ~[sqljdbc42.jar:?]
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:426) ~[sqljdbc42.jar:?]
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:372) ~[sqljdbc42.jar:?]
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:6276) ~[sqljdbc42.jar:?]
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1793) ~[sqljdbc42.jar:?]
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:184) ~[sqljdbc42.jar:?]
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:159) ~[sqljdbc42.jar:?]
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeUpdate(SQLServerPreparedStatement.java:315) ~[sqljdbc42.jar:?]
at com.dotcms.repackage.net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22) ~[dot.hibernate-2.1.7_2.jar:?]
at com.dotcms.repackage.net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:462) ~[dot.hibernate-2.1.7_2.jar:?]
at com.dotcms.repackage.net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:436) ~[dot.hibernate-2.1.7_2.jar:?]
at com.dotcms.repackage.net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:37) ~[dot.hibernate-2.1.7_2.jar:?]
at com.dotcms.repackage.net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2449) ~[dot.hibernate-2.1.7_2.jar:?]
at com.dotcms.repackage.net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2435) ~[dot.hibernate-2.1.7_2.jar:?]
at com.dotcms.repackage.net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2392) ~[dot.hibernate-2.1.7_2.jar:?]
at com.dotcms.repackage.net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2261) ~[dot.hibernate-2.1.7_2.jar:?]
at com.dotmarketing.db.HibernateUtil.saveWithPrimaryKey(HibernateUtil.java:1037) ~[dotcms_4.2.2_999999.jar:?]
at com.dotmarketing.portlets.workflows.business.WorkflowFactoryImpl.saveWorkflowTask(WorkflowFactoryImpl.java:1125) ~[dotcms_4.2.2_999999.jar:?]
at com.dotmarketing.portlets.workflows.business.WorkflowAPIImpl.saveWorkflowTask_aroundBody48(WorkflowAPIImpl.java:380) ~[dotcms_4.2.2_999999.jar:?]
at com.dotmarketing.portlets.workflows.business.WorkflowAPIImpl$AjcClosure49.run(WorkflowAPIImpl.java:1) ~[dotcms_4.2.2_999999.jar:?]
at org.aspectj.runtime.reflect.JoinPointImpl.proceed(JoinPointImpl.java:149) ~[aspectjrt-1.8.10.jar:?]
at com.dotcms.aspects.aspectj.AspectJDelegateMethodInvocation.proceed(AspectJDelegateMethodInvocation.java:43) ~[dotcms_4.2.2_999999.jar:?]
at com.dotmarketing.db.LocalTransaction.wrapReturnWithListeners(LocalTransaction.java:39) ~[dotcms_4.2.2_999999.jar:?]
at com.dotcms.aspects.interceptors.WrapInTransactionMethodInterceptor.invoke(WrapInTransactionMethodInterceptor.java:23) ~[dotcms_4.2.2_999999.jar:?]
at com.dotcms.aspects.aspectj.WrapInTransactionAspect.invoke(WrapInTransactionAspect.java:41) ~[dotcms_4.2.2_999999.jar:?]
at com.dotmarketing.portlets.workflows.business.WorkflowAPIImpl.saveWorkflowTask(WorkflowAPIImpl.java:379) ~[dotcms_4.2.2_999999.jar:?]
at com.dotcms.enterprise.publishing.remote.handler.ContentWorkflowHandler.handleContentWorkflow(ContentWorkflowHandler.java:131) ~[ee_clean.jar:?]
... 4 more
[10/01/18 16:52:00:587 CST] ERROR lang.String: Error Publishing: com.dotcms.publishing.DotPublishingException: Unable to flush Hibernate Session
[10/01/18 16:52:00:587 CST] INFO rest.PublishThread: Finished bundle publish process
Perhaps the transaction triggered at ContentHandler level is not yet committed, therefore it fails at saving this workflow task because nothing has been written to DB/Index yet.
Context
As reported on this ticket: https://dotcms.zendesk.com/agent/tickets/94957 The problem comes when a Content is pushed between environments via Workflows. Despite the checkin process is triggered just fine once the ContentHandler is triggered, the ContentWorkflowHandler cannot store this content's Workflow Tasks because they're still not stored in the DB.
Your Environment
- dotCMS version used: 4.2.2
- Browser Name and version: Any Browser
- Operating System and version: Any OS.
- Application Server and version: Any application server.
- Java Brand and version: Any Java version
- Database and version: any Db.
- Application module (if apply):
Note: The issue with WorkflowTasks is triggered once the code that was recently committed is in place, meaning that, despite it sets some necessary values for Contents being processed at PP time, it doesn't solve the race condition as explained in the ticket's description.
@jtesser this is the issue we were talking about this day. I managed to add these improvements as discussed via Slack, but I'm afraid this is more related to something else.
So far this cannot be reproduced with a regular Workflow Scheme and using the existing ones from Starter.
After further debugging, the Workflow task associated with this content being pushed is referencing a content that, despite the ContentHandler has saved without issues, it belongs to a transaction that is not yet committed
https://github.com/dotCMS/core/blob/master/dotCMS/src/main/java/com/dotcms/publisher/receiver/BundlePublisher.java#L211
therefore, it fails.
Debug info:
Receiver DB: see the content hasn't been fully committed

PR Core: https://github.com/dotCMS/core/pull/13378 PR EE: https://github.com/dotCMS/enterprise-2.x/pull/574
Passed QA. Tested on master branch. Win7 Pro SP1 / SQLServer 2012 / Chrome v54.0.2840.98 / Tomcat 8 / Java 8