Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support recursive types #2011

Closed
drewwells opened this issue Mar 2, 2021 · 2 comments · Fixed by #2022
Closed

Support recursive types #2011

drewwells opened this issue Mar 2, 2021 · 2 comments · Fixed by #2022

Comments

@drewwells
Copy link
Contributor

drewwells commented Mar 2, 2021

🚀 Feature

#1437 removed the ability to use recursive types. We used these in protoc-gen-gorm to created nested query structures. We parse SQL where clauses into an AST tree ie. WHERE group=acme AND tag=recent. The issue is that this syntax can have multiple layers of logical operators (AND OR).

WHERE (group='acme' AND tag  = 'recent') or tag = 'override')

Now that nested query parameters are specifically rejected, we are unable to parse these nested structures. I would like to be able to have recursive types to build trees. Here's an example proto definition. One of the possible parameters of LogicalOperator is LogicalOperator. As openapiv2 plugin inspects this, it returns the error: panic: recursive types are not allowed for query parameters, cycle found on ".infoblox.api.LogicalOperator"

https://github.com/infobloxopen/atlas-app-toolkit/blob/master/query/collection_operators.proto#L83

message LogicalOperator {
    oneof left {
        LogicalOperator left_operator = 1;
        StringCondition left_string_condition = 2;
        NumberCondition left_number_condition = 3;
        NullCondition left_null_condition = 4;
        StringArrayCondition left_string_array_condition = 11;
        NumberArrayCondition left_number_array_condition = 12;
    }
    oneof right {
        LogicalOperator right_operator = 5;
        StringCondition right_string_condition = 6;
        NumberCondition right_number_condition = 7;
        NullCondition right_null_condition = 8;
        StringArrayCondition right_string_array_condition = 13;
        NumberArrayCondition right_number_array_condition = 14;
    }
    enum Type {
        AND = 0;
        OR = 1;
    }
    Type type = 9;
    bool is_negative = 10;
}
@johanbrandhorst
Copy link
Collaborator

Hi Drew, thanks for the issue. It seems to me the original block on recursive types in query parameters was because it was causing an infinite loop in the parsing (#1167). I'd be happy to reintroduce recursive types as long as we have a plan to deal with that issue, which may mean detecting loops and short circuiting some recursion instead of outright disallowing the messages.

I think there's plenty of prior art here to study, but if you're unsure where to start, #1266 and #1437 are probably good places.

@drewwells
Copy link
Contributor Author

I agree on the infinite loop piece. I think starting with type detection made sense. We just need add counters to them. If type encountered 1000 times, panic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants