a8m / a8m/rql

Circular Struct Fields goes into infinite loop

Aperta
#53 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Go
Stelle
367
Fork
43
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

If the struct model used refers to any field with same type as that of model directly or indirectly in downstream dependencies then parser creation goes into infinite loop and program never proceeds. Example of such model. ( here Manager is of type User )
`type User struct {
ID uint ```gorm:"primary_key" rql:"filter,sort"\```
ManagerId *uint
Manager *User
DirectReports []User ```gorm:"foreignKey:ManagerId"\```
Admin bool ```rql:"filter"```
Name string ```rql:"filter"```
Tags datatypes.JSONSlice[string] ```rql:"filter"```
AddressName string ```rql:"filter"```
CreatedAt time.Time ```rql:"filter,sort"```
}`
I propose here two possible solutions
1. We introduce a `nested` tag like filter and sort and if a field of type struct is marked nested then only process it. This breaks the convention yet i have already forked this repo and wrote a code which works with this.
2. Generate all things parser does at run time ( on the fly while parsing queries and not while creating parser) and don't even preprocess model with parser and in doing so we can break loop till all fields refered in query are are parsed.

Would be happy to discuss both the approaches ( or if there could be any other ) and create necessary PR to fix this.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

The issue is in the parser creation logic when handling circular struct fields like a User with a *User Manager field. Look at the parser generation code, likely in the root directory or a parser/ subdirectory. Examine how struct fields are traversed to detect cycles. The fix requires understanding the parser's preprocessing phase and possibly adding cycle detection or a 'nested' tag. Test with the provided User struct example to reproduce the infinite loop.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
go
Ambito
backend, databases
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.