dolt: BUG: BEFORE UPDATE Trigger Not Working in Dolt

Description

There appears to be an issue with BEFORE UPDATE triggers in Dolt. While BEFORE INSERT triggers function correctly, identically structured BEFORE UPDATE triggers do not execute as expected.

Steps to Reproduce

  1. Create a test table with a primary key that should be auto-generated:
CREATE TABLE test (
    unique_id VARCHAR(32) NOT NULL PRIMARY KEY,
    region VARCHAR(16),
    year INT
);
  1. Create a BEFORE INSERT trigger to generate the primary key:
CREATE TRIGGER before_insert_test
BEFORE INSERT ON test
FOR EACH ROW
BEGIN
    SET NEW.unique_id = MD5(CONCAT(NEW.region, '|', NEW.year));
END;
  1. Create an identical BEFORE UPDATE trigger:
CREATE TRIGGER before_update_test
BEFORE UPDATE ON test
FOR EACH ROW
BEGIN
    SET NEW.unique_id = MD5(CONCAT(NEW.region, '|', NEW.year));
END;
  1. Insert a test record:
INSERT INTO test (region, year) VALUES ('North', 2023);

✅ This works correctly - the unique_id is generated.

  1. Update the record:
UPDATE test SET region = 'South' WHERE year = 2023;

❌ The unique_id is not updated to reflect the new region value.

Expected Behavior

The BEFORE UPDATE trigger should fire and update the unique_id field with a new MD5 hash based on the updated values.

Actual Behavior

The BEFORE UPDATE trigger appears not to execute at all, as the unique_id remains unchanged after update operations.

Environment

  • Dolt version: Dolt 1.50.0
  • Operating system: MacOS

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (8 by maintainers)

Most upvoted comments

Hey @Mickychen00 , we found the issue and have a fix merged. It’s currently making it’s way to dolt main and we’ll have a release out for you either today or early next week!

Hey @Mickychen00, I see; this makes a lot more sense. I’m able to reproduce the issue, and I’m working on a fix now!

@Mickychen00 , thanks for using Dolt! We’d love to learn more about your use case. Feel free to email me or swing by our Discord if you want to share.