8000 Circular Struct Fields goes into infinite loop · Issue #53 · a8m/rql · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content 8000
Circular Struct Fields goes into infinite loop #53
Open
@atmnksd

Description

@atmnksd

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0