edgedb / edgedb-rust

The official Rust binding for EdgeDB
https://edgedb.com
Apache License 2.0
214 stars 26 forks source link

Weird `ProtocolEncodingError` in Rust #303

Open jollygreenlaser opened 6 months ago

jollygreenlaser commented 6 months ago

I have a query that works fine in UI and CLI but dies in code (Rust) with ProtocolEncodingError which seems relatively rare.

It's a query selecting one of two options of an abstract type, with the same struct in rust. The query was working fine with both types using multi hop links in filters, but I refactored it after my discovery that subqueries were more performant. (see: https://discord.com/channels/841451783728529451/1220216804052308028)

After the refactor - same shape for the output, just a different way to filter for the object - I got the ProtocolEncodingError on one of the two types. The other works fine.

I narrowed it down to one computed field causing the issue. It looked something like:

is_done := assert_single(([is ThingA].subset.done ?? false) or
            ([is ThingA].subset.group.status ?? [is ThingB].group.status) = Status.Complete),

Where group is the same type on both, just from different levels of linkage.

What was super weird - beyond this error only happening in code and not UI/CLI, and only on one of the two types - is that the error would go away with almost any removal from that statement. I could remove almost any of the conditions that create that boolean and it would stop throwing the error.

is_done := assert_single(([is ThingA].subset.done ?? false) or
            ([is ThingA].subset ?? [is ThingB]).group.status = Status.Complete),

This is what I switched to so that I could retain the same logic but not hit the error. Super unclear why this mattered. Curious if others have encountered this or how to avoid hitting it. Nightmare to debug.