{"record":{"id":"d9d109809e5daaa3","repo":"ankane/pghero","slug":"pg-query-required-for-filter-data","errorCode":null,"errorMessage":"pg_query required for filter_data","messagePattern":"pg_query required for filter_data","errorType":"exception","errorClass":"PgHero::Error","httpStatus":null,"severity":"error","filePath":"lib/pghero/database.rb","lineNumber":110,"sourceCode":"    end\n\n    # must check keys for booleans\n    def filter_data\n      unless defined?(@filter_data)\n        @filter_data =\n          if config.key?(\"filter_data\")\n            config[\"filter_data\"]\n          elsif PgHero.config.key?(\"filter_data\")\n            PgHero.config.key?(\"filter_data\")\n          else\n            PgHero.filter_data\n          end\n\n        if @filter_data\n          begin\n            require \"pg_query\"\n          rescue LoadError\n            raise Error, \"pg_query required for filter_data\"\n          end\n        end\n      end\n\n      @filter_data\n    end\n\n    private\n\n    # check adapter lazily\n    def connection_model\n      unless @adapter_checked\n        # rough check for Postgres adapter\n        # keep this message generic so it's useful\n        # when empty url set in Docker image pghero.yml\n        unless @connection_model.connection_db_config.adapter.to_s.match?(/postg/i)\n          raise Error, \"Invalid connection URL\"\n        end","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/ankane/pghero/blob/7edb57986ffd36f9d64f0830c4ccc90a5eac46d6/lib/pghero/database.rb#L92-L128","documentation":"PgHero's filter_data feature (masking sensitive data in query text) needs the pg_query gem to parse SQL. When filter_data resolves to truthy - via the database's config key, the global PgHero config, or ENV[\"PGHERO_FILTER_DATA\"] - Database#filter_data attempts require \"pg_query\"; if the gem is not in the bundle it raises Error \"pg_query required for filter_data\".","triggerScenarios":"Setting filter_data: true in config/pghero.yml (per-database or top level) without gem \"pg_query\" in the Gemfile; setting the PGHERO_FILTER_DATA environment variable (e.g. in Docker/k8s) in an app whose bundle lacks pg_query.","commonSituations":"Enabling data filtering after reading the security docs but skipping the gem step; environment variables copied from another deployment that did include the gem; CI environments built from a reduced Gemfile.","solutions":["Add gem \"pg_query\" to the Gemfile and run bundle install","If you do not actually need data filtering, remove the filter_data key from pghero.yml and unset PGHERO_FILTER_DATA","Verify with Gem.loaded_specs.key?(\"pg_query\") in the environment where the error occurs"],"exampleFix":"# Gemfile - before\ngem \"pghero\"\n\n# Gemfile - after\ngem \"pghero\"\ngem \"pg_query\"\n# then run: bundle install","handlingStrategy":"validation","validationCode":"# fail fast at boot when the feature is on but the gem is absent\nif PgHero.filter_data && !Gem.loaded_specs.key?(\"pg_query\")\n  raise \"filter_data is enabled but the pg_query gem is not in the bundle\"\nend","typeGuard":null,"tryCatchPattern":"begin\n  PgHero.database.filter_data\nrescue PgHero::Error => e\n  # degrade gracefully: disable filtering rather than breaking the dashboard\n  Rails.logger.warn(\"#{e.message} - disabling filter_data\")\n  retry_without_filter_data\nend","preventionTips":["Add gem \"pg_query\" in the same commit that enables filter_data","Keep PGHERO_FILTER_DATA out of environments whose bundles are trimmed"],"tags":["pghero","missing-gem","ruby","bundler"],"backgroundTag":"missing-dependency","analyzedSha":"7edb57986ffd36f9d64f0830c4ccc90a5eac46d6","analyzedAt":"2026-08-21T17:33:54.942Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}