Alias model names that collide with enum names in generated services
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 35/100
Direzione di ricerca
Inizia individuando i template Python e i dieci confronti inline dei nomi dei modelli descritti nell’issue, inclusi api.twig e file.twig. Leggi il comportamento esistente del suffisso Model per le collisioni dei nomi dei servizi e getServiceEnumName, quindi traccia come un filtro condiviso getServiceModelName(service, spec) coprirebbe import, annotazioni, docstring, argomenti del modello e membri di Union; il lavoro è completato quando la regola di collisione viene risolta in modo coerente in tutti questi punti.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
🔖 Feature description
A spec is free to name an enum after a model. When it does, the Python generator emits two imports of the same name into one service module and the second silently wins:
from ..models.addon import Addon # response model
from ..enums.addon import Addon # enum for get_addon_price — shadows the model
def get_addon(self, organization_id: str, addon_id: str) -> Addon:
...
return self._parse_response(response, model=Addon)
Four methods in the Console Python SDK's organizations service then raised AttributeError: type object 'Addon' has no attribute 'model_validate' — get_addon, create_baa_addon, create_premium_geo_db_addon, confirm_addon_payment. It generated, imported, compiled and passed black --check; only calling it failed.
That instance was fixed in the spec by renaming the enum (Addon → AddonKey), which is the right fix for that collision. This issue is about the generator not depending on specs avoiding the name.
The templates already have the mechanism: a model whose name collides with its own service is imported under a Model suffix, e.g. from ..models.project import Project as ProjectModel in services/project.py. The proposal is to make that a general rule — alias a model when its name collides with the service or with any enum the same module imports — and to resolve it in one place.
🎤 Pitch
Today the collision check is an inline template comparison duplicated across ten sites in the Python templates: the three import branches, the return annotation, the generic [T] annotation, the docstring Returns block, the model= argument in api.twig and file.twig, and the Union[...] members. Adding the enum case means editing all ten and keeping them in step, which is why the enum case is currently missing from all ten at once. A single filter — model | getServiceModelName(service, spec) — would return the local name for every one of those sites, so the rule is stated once.
Worth deciding as part of this:
- Which side gets renamed. Aliasing the model keeps enum names stable for callers, matching the existing service-name rule. Aliasing the enum instead would be a bigger break, since enums appear in user call sites.
- Which languages need it. Python is the sharp case: two module-level imports of one name shadow silently. TypeScript, Dart, Go and Kotlin either namespace models (
Models.Addon,models.Addon) or fail at compile time, so they surface it immediately. A shared helper onLanguagewith per-language opt-in would suit the ones that need it. - Whether the generator should also fail loudly. A validation pass over the spec — "enum X collides with model X" — would catch the shape at generation time in every language, including any where aliasing is not the right answer.
Prior art in this repo: the Model suffix for a model matching its service name; the as {{ enumRef }} alias already emitted by getServiceEnumName when two enums in a service share a name.
👀 Have you spent some time to check if this issue has been raised before?
Yes.
🏢 Have you read the Code of Conduct?
Yes.
- Lingua principale
- Twig
- Stelle
- 330
- Fork
- 212
- Merge medio
- 12h 3m
- PR unite (30g)
- 131
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun 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 appwrite/sdk-generator
-
🐛 Bug Report: Execution.fromMap throws Bad state: No element when server doesn't return resourceType (pre-Sites serversForse di nuovo libera @Aakriti7-giti l’ha presa 80 giorni fa e non c’è nessuna pull request aperta. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
appwrite/sdk-generator#1858 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Generate Push by default for SDKs that already released itForse di nuovo libera @ChiragAgg5k l’ha presa 35 giorni fa e non c’è nessuna pull request aperta. Aperta
appwrite/sdk-generator#2043 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 45/100
appwrite/sdk-generator#1996 ·
I maintainer di solito rispondono entro 1 giorno
-
📚 Documentation: Add Vale linting for all generated docs and examplesForse già presa @kekubhai l’ha presa 75 giorni fa. Aperta
appwrite/sdk-generator#1822 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Dependency DashboardAperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 15/100
appwrite/sdk-generator#1628 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di appwrite/sdk-generator
Issue simili
-
bot:ai-assisted component:platform-js status:untriaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
midnightntwrk/platform-js#69 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
dagster-io/skills#80 ·
-
cc_wrapper crashes with ValueError on Windows when a path is on another driveForse già presa @TrapsterDK l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 79/100
tweag/rules_haskell#2492 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
neuralmagic/crucible#465 ·
I maintainer di solito rispondono entro 1 giorno
-
aws_ssm: Windows commands fail with "I/O operation on closed file" after reconnecting (stale _windows_executor)Forse già presa @DBloodworth95 l’ha presa oggi. Apertaneeds_triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
ansible-collections/amazon.aws#3247 ·
I maintainer di solito rispondono entro 4 giorni