| 173 | |
| 174 | |
| 175 | def append_query_params(url: str | None, params: dict) -> str: |
| 176 | from litellm._logging import verbose_proxy_logger |
| 177 | |
| 178 | verbose_proxy_logger.debug("url: %s", url) |
| 179 | verbose_proxy_logger.debug("params: %s", params) |
| 180 | if not isinstance(url, str) or url == "": |
| 181 | # Preserve previous startup behavior when DATABASE_URL is absent. |
| 182 | # Returning an empty string avoids urlparse type errors in test/dev flows. |
| 183 | verbose_proxy_logger.warning("append_query_params received empty or non-string URL, returning empty string") |
| 184 | return "" |
| 185 | parsed_url: Final = urlparse.urlparse(url) |
| 186 | parsed_query: Final = urlparse.parse_qs(parsed_url.query) |
| 187 | parsed_query.update(params) |
| 188 | encoded_query: Final = urlparse.urlencode(parsed_query, doseq=True) |
| 189 | modified_url: Final = urlparse.urlunparse(parsed_url._replace(query=encoded_query)) |
| 190 | return modified_url |
| 191 | |
| 192 | |
| 193 | def resolve_v2_migration_resolver(*, use_legacy_flag: bool, env_value: str | None) -> bool: |