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

Seemingly unnecessary error on type unions #7160

Open
jollygreenlaser opened this issue Apr 4, 2024 · 2 comments
Open

Seemingly unnecessary error on type unions #7160

jollygreenlaser opened this issue Apr 4, 2024 · 2 comments

Comments

@jollygreenlaser
Copy link

  • EdgeDB Version: EdgeDB Version: 4.4+596d0e4 on Ubuntu 22.04.3 LTS
  • EdgeDB CLI Version: EdgeDB CLI 4.1.0+a8fe4d7
SchemaError: it is illegal to create a type union that causes a computed property 'fee' to mix with other versions of the same property 'fee'

Coming from:

with
event := (select Event filter .id = <uuid>$0)
patrons := {
  (select (insert Patron {
    user := (select User filter .username = 'Alice'),
    event := event,
  }) {
    fee := event.fee,
  }),
  (select (insert Patron {
    user := (select User filter .username = 'Bob'),
    event := event,
  }) {
    fee := event.fee,
  }),
}
select {
  event := event,
  patrons := patrons,
  total := sum(patrons.fee),
  ...
}

This query is being string built because when it was JSON input it took forever to run and now the string built version is actually performant. So the select (insert Patron...) { fee } part used to be a for over JSON.

It worked fine when it was JSON. Now I get that error. Despite fee being float32 - unclear why it doesn't like the type?

I'm working to refactor the query to hopefully fix this but unclear why it's even an issue.

@msullivan
Copy link
Member

We don't support doing unions of types with computed properties. Eventually we'll fix this, but it's tricky for a few reasons.

Try putting the shape on the outside of the union?

@jollygreenlaser
Copy link
Author

In this case, my refactor was to remove the computed property and change the final select to total := sum((select patrons { fee := .event.fee }).fee). The tricky part here of course being that patrons.event.fee won't work because the events ends up as an intermediate set that is implicitly distinct. Which I believe was what I was trying to dodge back when I originally wrote this.

Thanks for the help. I could see supporting this being mildly useful but not nearly important enough if there's tricky stuff under the hood.

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

No branches or pull requests

2 participants