lib/hiera/backend/mysql2_backend.rb in hiera-mysql-backend-0.0.2 vs lib/hiera/backend/mysql2_backend.rb in hiera-mysql-backend-0.0.3

- old
+ new

@@ -14,12 +14,15 @@ Hiera.debug("Hiera MySQL2 initialized") end def lookup(key, scope, order_override, resolution_type) - # default answer just to make it easier on ourselves - results = nil + # default answer is set to nil otherwise the lookup ends up returning + # an Array of nils and causing a Puppet::Parser::AST::Resource failed with error ArgumentError + # for any other lookup because their default value is overwriten by [nil,nil,nil,nil] + # so hiera('myvalue', 'test1') returns [nil,nil,nil,nil] + results = nil Hiera.debug("looking up #{key} in MySQL2 Backend") Hiera.debug("resolution type is #{resolution_type}") Backend.datasources(scope, order_override) do |source| @@ -62,9 +65,11 @@ data = client.query(query).to_a Hiera.debug("Mysql Query returned #{data.size} rows") rescue => e Hiera.debug e.message data = nil + ensure + client.close end return data end