fix(postgres): TypeError when max_tables is not explicitly specified #22009
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When max_tables is not specified in collect_schemas config, the default value is stored as float (300.0) instead of int. This causes a TypeError when used as a slice index in line 613.
What does this PR do?
Fixes a
TypeErrorwhen collecting PostgreSQL schema metadata without explicitly specifyingmax_tablesin the configuration. The PR converts themax_tablesvalue to an integer before using it as a list slice index.Motivation
When deploying the Datadog Agent with the Kubernetes Operator and enabling schema collection with only
collect_schemas.enabled: true(without specifyingmax_tables), the agent fails with:Error collecting schema metadata: slice indices must be integers or None or have an index method
Root cause: The
max_tablesconfig value is typed asOptional[float]and defaults to300.0(float). At line 613 inmetadata.py, this float value is used as a slice index (table_info[:limit]), which Python rejects because slice indices must be integers.Fix: Convert
max_tablesto int with fallback to default value at line 590:Review checklist (to be filled by reviewers)
qa/skip-qalabel if the PR doesn't need to be tested during QA.backport/<branch-name>label to the PR and it will automatically open a backport PR once this one is merged