Bug #61860 Workbench crashes while attempting to synchronize model
Submitted: 14 Jul 2011 1:43 Modified: 13 Jun 2013 21:39
Reporter: Carl Robinson Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Workbench: Modeling Severity:S1 (Critical)
Version:5.2.34 GA (Win32) OS:Microsoft Windows (Vista SP2, XP SP3)
Assigned to: CPU Architecture:Any
Tags: model, synchronize, trigger, workbench
Triage: Needs Triage: D1 (Critical)

[14 Jul 2011 1:43] Carl Robinson
Description:
Workbench shuts down with a Windows "stopped working" message while attempting to synchronize a model. Appears to be related to processing of triggers as the condition only appeared after implementing a trigger and performing an unrelated schema change (synchronization was fetching existing schema info from the db).

Synchronization appears to complete successfully if the triggers do not exist in the database (synchronization will add them, and then fail on any subsequent change after triggers are added).

Additional: Server version in use: 5.1.56 (Win64)

How to repeat:
1.  Create a simple workbench model equivalent to the following SQL, and forward engineer to create the database:

CREATE SCHEMA IF NOT EXISTS `CrashTestCase` DEFAULT CHARACTER SET latin1 ;
USE `CrashTestCase` ;

CREATE  TABLE IF NOT EXISTS `CrashTestCase`.`Account` (
  `idAccount` INT NOT NULL AUTO_INCREMENT ,
  `Type` ENUM('Asset','Liability','Equity','Revenue','Expense','Contra-Asset','Contra-Liability','Contra-Equity','Contra-Revenue','Contra-Expense') NOT NULL ,
  `IsDebit` TINYINT(1)  NULL ,
  `IsCredit` TINYINT(1)  NULL ,
  PRIMARY KEY (`idAccount`) )
ENGINE = InnoDB;

USE `CrashTestCase`;

DELIMITER $$

USE `CrashTestCase`$$

CREATE TRIGGER AccountBeforeInsert BEFORE INSERT ON Account FOR EACH ROW
BEGIN
  SET
    New.IsDebit = IF((New.Type = 'Asset') OR (New.Type = 'Expense') OR (New.Type = 'Contra-Liability') OR (New.Type = 'Contra-Equity') OR (New.Type = 'Contra-Revenue'), TRUE,FALSE),
    New.IsCredit = IF((New.Type = 'Asset') OR (New.Type = 'Expense') OR (New.Type = 'Contra-Liability') OR (New.Type = 'Contra-Equity') OR (New.Type = 'Contra-Revenue'), FALSE,TRUE);
    END
    $$

USE `CrashTestCase`$$

CREATE TRIGGER AccountBeforeUpdate BEFORE UPDATE ON Account FOR EACH ROW
BEGIN
  SET
    New.IsDebit = IF((New.Type = 'Asset') OR (New.Type = 'Expense') OR (New.Type = 'Contra-Liability') OR (New.Type = 'Contra-Equity') OR (New.Type = 'Contra-Revenue'), TRUE,FALSE),
    New.IsCredit = IF((New.Type = 'Asset') OR (New.Type = 'Expense') OR (New.Type = 'Contra-Liability') OR (New.Type = 'Contra-Equity') OR (New.Type = 'Contra-Revenue'), FALSE,TRUE);
    END
    $$

DELIMITER ;

2. Alter the workbench model by adding a column to the table.

3. Attempt to synchronize the model (propagate the model change to the database).
[14 Jul 2011 11:04] Miguel Solorzano
I couldn't repeat on Vista 64-bit against a 5.5.15 built source server.
[14 Jul 2011 14:29] Carl Robinson
Found that crash also occurs if the trigger sql is replaced with a view.

I.e. drop IsCredit,IsDebit from the previous example, create a view like this:

CREATE VIEW `Accounting`.`AccountView` AS
SELECT *,IF((Type = 'Asset') OR (Type = 'Expense') OR (Type = 'Contra-Liability') OR (Type = 'Contra-Equity') OR (Type = 'Contra-Revenue'), 1,0) AS IsDebit,
    IF((Type = 'Asset') OR (Type = 'Expense') OR (Type = 'Contra-Liability') OR (Type = 'Contra-Equity') OR (Type = 'Contra-Revenue'), 0,1) AS IsCredit
FROM Account

Synchronize this, then add a column 'Test' as the default VARCHAR(45) (NULL) to the Account table in the model and synchronize again.

Problem does not occur if view is dropped from schema before synchronizing.

Problem is not related to column being named 'Type' (occurs if column is named 'AccountType'), occurs for different styles of enumeration values - spaces instead of hyphens, or no embedded space/punctuation (e.g. 'ContraAsset')
[15 Jul 2011 8:00] Valeriy Kravchuk
Verified just as described on 32-bit Windows XP with .mwb file uploaded. 

I've just added newcol varchar(45) to the table after forward engineering .mwb file to MySQL server 5.1.56 and tried to synchronize. Got a crash of Workbench.
[13 Jun 2013 21:39] Philip Olson
Fixed as of the upcoming MySQL Workbench 6.0.2 public beta release, and here's the changelog entry:

Synchronization would sometimes fail and crash MySQL Workbench with models
that included triggers.

Thank you for the bug report.