Skip to content

Commit 1bad8ae

Browse files
committed
Fixes edge-case with dropping pre-existing users with grants
If a user exists in the database upon first Puppet run (for example, in the case of loading a database snapshot) and the run sets that user's :ensure attribute to 'absent', the mysql_grant provider will throw an error when the dependency chain causes it to try to destroy the grants associated with that user because the DROP statement from the mysql_user provider already removed the grants. To fix, we must check if the user exists before revoking the grants.
1 parent 0149481 commit 1bad8ae

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/puppet/provider/mysql_grant/mysql.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ def revoke(user, table, revoke_privileges = ['ALL'])
114114
end
115115

116116
def destroy
117-
revoke(@property_hash[:user], @property_hash[:table])
117+
# if the user was dropped, it'll have been removed from the user hash
118+
# as the grants are alraedy removed by the DROP statement
119+
if self.class.users.include? @property_hash[:user]
120+
revoke(@property_hash[:user], @property_hash[:table])
121+
end
118122
@property_hash.clear
119123

120124
exists? ? (return false) : (return true)

0 commit comments

Comments
 (0)