ITADN

[postgres] TypeError when collecting schema metadata without explicitly specifying max_tables

#22008Closedayoubbts 创建于 2025-11-28
A
ayoubbtscommented
## What happened When deploying the Datadog Agent with the Kubernetes Operator and enabling schema collection without explicitly specifying `max_tables`, the agent fails to collect schema metadata with the following error: `Error collecting schema metadata: slice indices must be integers or None or have an index method` ## What I expect Schema collection should work with default values when `max_tables` is not explicitly specified in the configuration. ## Steps to reproduce 1. Deploy Datadog Agent using the Datadog Operator 2. Configure postgres check with: ```yaml collect_schemas: enabled: true # max_tables not specified, should use default value of 300 ``` 3. Observe error in agent logs ## Environment Agent Version: 7.72.1 (cluster-agent) Integration Version: postgres 7.72.1 Deployment Method: Datadog Kubernetes Operator OS: Kubernetes ## Additional context Root cause [In `metadata.py` line 590](https://github.com/DataDog/integrations-core/blob/7.72.1/postgres/datadog_checks/postgres/metadata.py#L590), `max_tables` is used directly from the config without type conversion: ```python limit = self._config.collect_schemas.max_tables ``` This causes a TypeError at line 613 when attempting to slice a list: ```python return table_info[:limit] # TypeError: slice indices must be integers ``` The issue is that that `max_tables` is typed as `Optional[float]` in [instance.py line 84](https://github.com/DataDog/integrations-core/blob/7.72.1/postgres/datadog_checks/postgres/config_models/instance.py#L84), but Python slicing requires integer indices ## Proposed fix Cast `max_tables` to int with fallback to default value: ```python limit = int(self._config.collect_schemas.max_tables) ``` ## Workaround Explicitly specify `max_tables` in the configuration: ```yaml collect_schemas: enabled: true max_tables: 500 # or any other value ```
关闭于 2025-12-02 2 条评论