Add a test for query key sorting in URL.render_as_string()
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 1/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 85/100
Direzione di ricerca
Leggi lib/sqlalchemy/engine/url.py e i test URLTest in test/engine/test_parseconnect.py. Aggiungi un caso con le stesse chiavi di query in ordini diversi, come i due URL nell’issue, e verifica che gli URL uguali abbiano lo stesso hash. Esegui python -m pytest test/engine/test_parseconnect.py; il lavoro è completato quando il test di regressione passa e fallirebbe se venisse rimossa l’ordinazione delle chiavi.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
There is no test to check if keys.sort() works in URL.render_as_string() (lib/sqlalchemy/engine/url.py).
The function itself is working correctly, so this is a suggestion to add a test to ensure the sort is working.
Sorting is necessary because __hash__() uses str(self). For example, without sorting, make_url("d://h/db?a=1&b=2") and make_url("d://h/db?b=2&a=1") are equal because __eq__() compares the query as a dict, but they have different hashes. So they would be treated as different keys in a dict or set.
All query strings in test/engine/test_parseconnect.py are already in alphabetical order, so the tests pass even if the sort is removed. (The full test suite also passes with the sort removed.)
I would be happy to send a PR with a test in URLTest if this is labeled "open for pull requests".
Optional link from https://docs.sqlalchemy.org which documents the behavior that is expected
No response
SQLAlchemy Version in Use
2.1.9 (main branch, commit 4e974a083)
DBAPI (i.e. the database driver)
pysqlite (Python’s built-in sqlite3), but no database connection is needed for this issue
Database Vendor and Major Version
SQLite (used to run the test suite; not related to this issue)
Python Version
3.12.4
Operating system
macOS 26.3.1
To Reproduce
from sqlalchemy.engine.url import make_url
a = make_url("d://h/db?a=1&b=2")
b = make_url("d://h/db?b=2&a=1")
print("equal:", a == b, "/ same hash:", hash(a) == hash(b), "/ set size:", len({a, b}))
# 1. With the current code:
# equal: True / same hash: True / set size: 1
#
# 2. Remove `keys.sort()` in URL.render_as_string() and run again:
# equal: True / same hash: False / set size: 2
#
# 3. With `keys.sort()` removed, the tests still pass:
# python -m pytest test/engine/test_parseconnect.py -> all passed
# python -m pytest test/ -n auto -> 0 failed
Error
No error is raised. The problem is that the tests still pass when keys.sort() is removed.
Additional context
No response
- Lingua principale
- Python
- Stelle
- 12.3k
- Fork
- 1.8k
- Merge medio
- 2g 10h
- PR unite (30g)
- 9
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di sqlalchemy/sqlalchemy
-
bug engine
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
sqlalchemy/sqlalchemy#13770 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
declared_attr.cascading fails to typecheck under mypy / pyright on documented usageForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Apertabug orm typing
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
sqlalchemy/sqlalchemy#13731 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
PostgreSQL multihost URL with bracketed IPv6 hosts raises ValueError: too many values to unpackForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Apertabug engine postgresql
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
sqlalchemy/sqlalchemy#13637 · 6 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
asyncpg dialect raises DBAPIError, not DataError, for SQLSTATE class 22 errorsForse già presa @HardMax71 l’ha presa 21 giorni fa. Apertabug code review in progress dialects
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
sqlalchemy/sqlalchemy#13636 · 19 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
documentation bugForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Apertadocumentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
sqlalchemy/sqlalchemy#13594 · 2 commenti · 5 reazioni ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di sqlalchemy/sqlalchemy
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
glossyio/traffic-monitor#312 ·
I maintainer di solito rispondono entro 1 giorno
-
local devenv exampleApertadocumentation enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
es-ude/elastic-ai.creator#1046 ·
I maintainer di solito rispondono entro 3 giorni
-
ENH: permit cachetools >= 7Apertafeature request
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
confident-ai/deepteam#306 ·
I maintainer di solito rispondono entro 1 giorno
-
SslLibrary crashes with unhandled OSError: port/proto not found on non-standard SSL portsForse già presa @himanchalkaushale l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
OWASP/Nettacker#1884 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno