Commit 855e19a
postgres: improve robustness of database name handling in schema collection (DataDog#23389)
* Improve robustness of database name handling in schema collection
Switch `_get_databases` to use `%s` parameterized placeholders passed
to `cursor.execute` instead of formatting values directly into the query
string. This applies to the autodiscovery IN clause as well as the
exclude/include regex filters, ensuring database names and filter
patterns are always properly handled regardless of their content.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* Add changelog entry for query parameterization fix
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* Escape percent literal in DATABASE_INFORMATION_QUERY for parameterized execution
psycopg treats % as a placeholder prefix whenever params are passed to
cursor.execute. The LIKE wildcard in the base query must be %% so it
renders as a literal % after substitution.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* Simplify _get_databases query construction
Build query and params before acquiring the connection, flatten
autodiscovery nesting, and use list multiplication for placeholder
generation.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>1 parent d7f8f86 commit 855e19a
2 files changed
Lines changed: 22 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
165 | | - | |
| 165 | + | |
166 | 166 | | |
167 | 167 | | |
168 | 168 | | |
| |||
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
204 | 223 | | |
205 | 224 | | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
| 225 | + | |
221 | 226 | | |
222 | 227 | | |
223 | 228 | | |
| |||
0 commit comments