From b5b8031b44dd14dcf697d8bf7b402160a3773733 Mon Sep 17 00:00:00 2001 From: jasquat <2487833+jasquat@users.noreply.github.com> Date: Mon, 25 Mar 2024 18:32:44 +0000 Subject: [PATCH] fix-human-task-guid-fk (#1260) * removed human_task_ibfk_5 from old migration file and updated task id removal migration to work with both mysql and postgres w/ burnettk * use sqlalchemy error classes instead of mysql w/ burnettk * mypy w/ burnettk * remove deprecated cypress config w/ burnettk --------- Co-authored-by: jasquat --- .../migrations/versions/0c7428378d6e_.py | 2 +- .../migrations/versions/3191627ae224_.py | 10 +++++++++- .../routes/tasks_controller.py | 2 +- spiffworkflow-frontend/cypress.config.js | 19 +++++++++---------- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/spiffworkflow-backend/migrations/versions/0c7428378d6e_.py b/spiffworkflow-backend/migrations/versions/0c7428378d6e_.py index 9fb330bf..b4cd4428 100644 --- a/spiffworkflow-backend/migrations/versions/0c7428378d6e_.py +++ b/spiffworkflow-backend/migrations/versions/0c7428378d6e_.py @@ -446,7 +446,7 @@ def upgrade(): sa.ForeignKeyConstraint(['completed_by_user_id'], ['user.id'], ), sa.ForeignKeyConstraint(['lane_assignment_id'], ['group.id'], ), sa.ForeignKeyConstraint(['process_instance_id'], ['process_instance.id'], ), - sa.ForeignKeyConstraint(['task_model_id'], ['task.id'], name='human_task_ibfk_5'), + sa.ForeignKeyConstraint(['task_model_id'], ['task.id']), sa.PrimaryKeyConstraint('id') ) with op.batch_alter_table('human_task', schema=None) as batch_op: diff --git a/spiffworkflow-backend/migrations/versions/3191627ae224_.py b/spiffworkflow-backend/migrations/versions/3191627ae224_.py index 52102cfb..9bcd5894 100644 --- a/spiffworkflow-backend/migrations/versions/3191627ae224_.py +++ b/spiffworkflow-backend/migrations/versions/3191627ae224_.py @@ -20,6 +20,9 @@ depends_on = None def is_mysql() -> bool: return dialect_name() == 'mysql' +def is_postgres() -> bool: + return dialect_name() == 'postgres' + def upgrade(): # ### commands auto generated by Alembic - please adjust! ### @@ -31,7 +34,12 @@ def upgrade(): with op.batch_alter_table('human_task', schema=None) as batch_op: batch_op.add_column(sa.Column('task_guid', sa.String(length=36), nullable=True)) - batch_op.drop_constraint('human_task_ibfk_5', type_='foreignkey') + + # sqlite does not seem to have this foreignkey constraint + if is_postgres(): + batch_op.drop_constraint('human_task_task_model_id_fkey', type_='foreignkey') + elif is_mysql(): + batch_op.drop_constraint('human_task_ibfk_5', type_='foreignkey') batch_op.drop_index('ix_human_task_task_model_id') batch_op.create_index(batch_op.f('ix_human_task_task_guid'), ['task_guid'], unique=False) batch_op.create_foreign_key('human_task_ibfk_task_guid', 'task', ['task_guid'], ['guid']) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/routes/tasks_controller.py b/spiffworkflow-backend/src/spiffworkflow_backend/routes/tasks_controller.py index e60abb8d..eded01c1 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/routes/tasks_controller.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/routes/tasks_controller.py @@ -11,7 +11,6 @@ from flask import jsonify from flask import make_response from flask import stream_with_context from flask.wrappers import Response -from MySQLdb import OperationalError # type: ignore from SpiffWorkflow.bpmn.exceptions import WorkflowTaskException # type: ignore from SpiffWorkflow.bpmn.workflow import BpmnWorkflow # type: ignore from SpiffWorkflow.task import Task as SpiffTask # type: ignore @@ -19,6 +18,7 @@ from SpiffWorkflow.util.task import TaskState # type: ignore from sqlalchemy import and_ from sqlalchemy import desc from sqlalchemy import func +from sqlalchemy.exc import OperationalError from sqlalchemy.orm import aliased from sqlalchemy.orm.util import AliasedClass diff --git a/spiffworkflow-frontend/cypress.config.js b/spiffworkflow-frontend/cypress.config.js index 5dfd2b03..6b2e9ad2 100644 --- a/spiffworkflow-frontend/cypress.config.js +++ b/spiffworkflow-frontend/cypress.config.js @@ -1,6 +1,6 @@ /* eslint-disable */ -const { defineConfig } = require("cypress"); -const { rm } = require("fs/promises"); +const { defineConfig } = require('cypress'); +const { rm } = require('fs/promises'); // yes use video compression in CI, where we will set the env var so we upload to cypress dashboard const useVideoCompression = !!process.env.CYPRESS_RECORD_KEY; @@ -8,15 +8,15 @@ const useVideoCompression = !!process.env.CYPRESS_RECORD_KEY; // https://github.com/cypress-io/cypress/issues/2522 const deleteVideosOnSuccess = (on) => { const filesToDelete = []; - on("after:spec", (_spec, results) => { + on('after:spec', (_spec, results) => { if (results.stats.failures === 0 && results.video) { filesToDelete.push(results.video); } }); - on("after:run", async () => { + on('after:run', async () => { if (filesToDelete.length) { console.log( - "after:run hook: Deleting %d video(s) from successful specs", + 'after:run hook: Deleting %d video(s) from successful specs', filesToDelete.length ); await Promise.all(filesToDelete.map((videoFile) => rm(videoFile))); @@ -33,15 +33,14 @@ if (process.env.SPIFFWORKFLOW_FRONTEND_URL) { } const cypressConfig = { - projectId: "crax1q", + projectId: 'crax1q', defaultCommandTimeout: 20000, - videoUploadOnPasses: false, chromeWebSecurity: false, e2e: { baseUrl: spiffWorkflowFrontendUrl, setupNodeEvents(on, config) { deleteVideosOnSuccess(on); - require("@cypress/grep/src/plugin")(config); + require('@cypress/grep/src/plugin')(config); return config; }, }, @@ -49,7 +48,7 @@ const cypressConfig = { // this scrolls away from the elements for some reason with carbon when set to top // https://github.com/cypress-io/cypress/issues/2353 // https://docs.cypress.io/guides/core-concepts/interacting-with-elements#Scrolling - scrollBehavior: "center", + scrollBehavior: 'center', }; if (!process.env.CYPRESS_RECORD_KEY) { @@ -57,4 +56,4 @@ if (!process.env.CYPRESS_RECORD_KEY) { cypressConfig.videoCompression = false; } -module.exports = defineConfig(cypressConfig) +module.exports = defineConfig(cypressConfig);