graphql-python / graphql-python/graphql-core-legacy
Usage of Asserts Breaks Code
- Vorherrschende Sprache
- Python
- Sterne
- 372
- Forks
- 175
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
This project uses asserts in a lot of places (I found about 100 cases) where they should **not** be used. They're being used to validate arguments to functions, where the normal Python way would be to use a `TypeError` or a `ValueError`. Assertions are essentially debug code, not code for validating arguments.
Any usage of optimize mode or Python (`-O` or `-OO`, or `PYTHONOPTIMIZE`) strips out assertions, making this code useless. That's very problematic if you're generating schema dynamically, as you won't get errors and this library will generate an invalid GraphQL schema.
At this point it's probably too late to change the uses of assert to a proper `TypeError` or `ValueError`, without a major version bump as dependent code in other projects may be catching `AssertionError`.
I'm proposing all instances of `assert foo, "Error"` be replaced with:
```python
if not foo:
raise AssertionError("Error") # Should be a TypeError
```
This will at least make the code work in optimize modes where assertions are stripped.
I'll gladly make a PR doing so, but it's hard to tell if this project is still actively developed.
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Rechercherichtung
Durchsuche das Repository nach den ungefähr 100 zur Argumentvalidierung verwendeten assert-Aufrufen, die im Issue beschrieben sind, und vergleiche ihr Verhalten bei normaler Ausführung und bei der Ausführung mit Python -O. Überprüfe jede betroffene Aufrufstelle auf ihre erwartete Fehlermeldung und bestätige, dass die optimierte Ausführung ungültige Eingaben weiterhin ablehnt, ohne die bestehende AssertionError-Kompatibilität zu ändern.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- graphql, python
- Bereich
- backend-api-design
- Issue-Typ
- Bug
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 25/100