From 9f2d277b2b3bbca1c5eaf492a425e24785232176 Mon Sep 17 00:00:00 2001 From: Jason St-Cyr Date: Mon, 9 Nov 2026 21:25:34 -0500 Subject: [PATCH 1/3] (GH-1761) Match MySQL unknown-database error by code, not locale text The mysql_database provider's self.instances rescued a missing database by matching the English string "Unknown database" in the error message from the mysql/mariadb client. Under a non-English server/client locale (e.g. German, which reports "Unbekannte Datenbank"), that match fails and the exception is re-raised, breaking prefetch for every mysql_database resource in the catalog. This surfaced via mysql::server::account_security, which declares `mysql_database { 'test': ensure => absent }`: once the database is removed on a first run, every subsequent run fails during prefetch under a non-English locale. Match on the numeric, locale-independent MySQL/MariaDB error code 1049 (ER_BAD_DB_ERROR) instead. Co-Authored-By: Claude Sonnet 5 --- lib/puppet/provider/mysql_database/mysql.rb | 7 ++++++- spec/unit/puppet/provider/mysql_database/mysql_spec.rb | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/puppet/provider/mysql_database/mysql.rb b/lib/puppet/provider/mysql_database/mysql.rb index 8e660e46a..face3c7d7 100644 --- a/lib/puppet/provider/mysql_database/mysql.rb +++ b/lib/puppet/provider/mysql_database/mysql.rb @@ -23,7 +23,12 @@ def self.instances(managed_databases = nil) attributes[k] = v end rescue Puppet::ExecutionFailure => e - raise unless e.message.include?('Unknown database') + # MySQL/MariaDB error 1049 is ER_BAD_DB_ERROR ("Unknown database"). + # Match on the numeric error code rather than the message text, since + # the text is localized (e.g. "Unbekannte Datenbank" under a German + # locale) and would otherwise fail to match, causing prefetch to + # raise for a database that is simply absent as desired. + raise unless e.message.match?(%r{ERROR 1049 }) next end diff --git a/spec/unit/puppet/provider/mysql_database/mysql_spec.rb b/spec/unit/puppet/provider/mysql_database/mysql_spec.rb index 4f0364c98..d7a5aad49 100644 --- a/spec/unit/puppet/provider/mysql_database/mysql_spec.rb +++ b/spec/unit/puppet/provider/mysql_database/mysql_spec.rb @@ -53,6 +53,16 @@ expect(databases).to eq(['managed_existing']) end + it 'skips managed databases that no longer exist under a non-English locale' do + allow(provider.class).to receive(:mysql_caller).with(["show variables like '%_database'", 'managed_existing'], 'regular').and_return("character_set_database latin1\ncollation_database latin1_swedish_ci\nskip_show_database OFF") # rubocop:disable Layout/LineLength + allow(provider.class).to receive(:mysql_caller) + .with(["show variables like '%_database'", 'managed_missing'], 'regular') + .and_raise(Puppet::ExecutionFailure, "Execution of '/usr/bin/mariadb -NBe show variables like '%_database' managed_missing' returned 1: ERROR 1049 (42000): Unbekannte Datenbank 'managed_missing'") # rubocop:disable Layout/LineLength + + databases = provider.class.instances(['managed_existing', 'managed_missing']).map(&:name) + expect(databases).to eq(['managed_existing']) + end + it 're-raises unexpected database lookup failures' do allow(provider.class).to receive(:mysql_caller).with(["show variables like '%_database'", 'managed_broken'], 'regular').and_raise(Puppet::ExecutionFailure, 'ERROR 1044 (42000): Access denied') From b92bb987561d3921a4f5ccd76787867a1a6ea8f0 Mon Sep 17 00:00:00 2001 From: Jason St-Cyr Date: Mon, 9 Nov 2026 21:30:56 -0500 Subject: [PATCH 2/3] Fix RuboCop Performance/StringInclude offense Use String#include? instead of a regex match with a literal-only pattern, per CI's RuboCop configuration. Co-Authored-By: Claude Sonnet 5 --- lib/puppet/provider/mysql_database/mysql.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/provider/mysql_database/mysql.rb b/lib/puppet/provider/mysql_database/mysql.rb index face3c7d7..87ffb6eae 100644 --- a/lib/puppet/provider/mysql_database/mysql.rb +++ b/lib/puppet/provider/mysql_database/mysql.rb @@ -28,7 +28,7 @@ def self.instances(managed_databases = nil) # the text is localized (e.g. "Unbekannte Datenbank" under a German # locale) and would otherwise fail to match, causing prefetch to # raise for a database that is simply absent as desired. - raise unless e.message.match?(%r{ERROR 1049 }) + raise unless e.message.include?('ERROR 1049 ') next end From 32b637540d7f4988cb74929207edeb8bdf79d74c Mon Sep 17 00:00:00 2001 From: Jason St-Cyr Date: Mon, 9 Nov 2026 21:43:56 -0500 Subject: [PATCH 3/3] Trimming down comments inserted by Claude --- lib/puppet/provider/mysql_database/mysql.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/puppet/provider/mysql_database/mysql.rb b/lib/puppet/provider/mysql_database/mysql.rb index 87ffb6eae..c95709390 100644 --- a/lib/puppet/provider/mysql_database/mysql.rb +++ b/lib/puppet/provider/mysql_database/mysql.rb @@ -23,11 +23,7 @@ def self.instances(managed_databases = nil) attributes[k] = v end rescue Puppet::ExecutionFailure => e - # MySQL/MariaDB error 1049 is ER_BAD_DB_ERROR ("Unknown database"). - # Match on the numeric error code rather than the message text, since - # the text is localized (e.g. "Unbekannte Datenbank" under a German - # locale) and would otherwise fail to match, causing prefetch to - # raise for a database that is simply absent as desired. + # MySQL/MariaDB error 1049 is ER_BAD_DB_ERROR ("Unknown database"). Match on the numeric error code to handle localized error text. raise unless e.message.include?('ERROR 1049 ') next