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

Named tuple params whose types also appear in the schema don't work #5789

Closed
abecciu opened this issue Jul 14, 2023 · 1 comment · Fixed by #5964
Closed

Named tuple params whose types also appear in the schema don't work #5789

abecciu opened this issue Jul 14, 2023 · 1 comment · Fixed by #5964
Assignees

Comments

@abecciu
Copy link

abecciu commented Jul 14, 2023

  • EdgeDB Version: 3.0+7d903be
  • EdgeDB CLI Version: 3.4.0+4d95a2c
  • OS Version: macOs 13

Steps to Reproduce:

Schema:

 type Meeting {
    required title -> str {
      constraint exclusive;
    };

    multi recurrence: str;

    creator_meta: tuple<display_name: str, email: str, id: str>;
    multi attendees_meta: tuple<
        display_name: str,
        email: str,
        rsvp_status: str,
        rsvp_comment: str,
        is_optional: bool,
        is_event_organizer: bool,
        additional_guests: int64,
        provider_meta: json,
    >;
  }
};

Query with Typescript Query Builder:

  const insertQ = e.params({
    title: e.str,
    recurrence: e.array(e.str),
    creator_meta: e.tuple({
      display_name: e.str,
      email: e.str,
      id: e.str,
    }),
    attendees_meta: e.array(
      e.tuple({
        display_name: e.str,
        email: e.str,
        rsvp_status: e.str,
        rsvp_comment: e.str,
        is_optional: e.bool,
        is_event_organizer: e.bool,
        additional_guests: e.int64,
        provider_meta: e.json,
      }),
    ),
  }, (params) => {
    return e.insert(e.Meeting, {
      title: params.title,
      recurrence: e.array_unpack(params.recurrence),
      creator_meta: params.creator_meta,
      attendees_meta: e.array_unpack(params.attendees_meta),
    });
  });

  const insertResult = await insertQ.run(client, {
    title: "Test",
    recurrence: ["RRULE:FREQ=WEEKLY;BYDAY=MO,WE,FR", "EXDATE:20210101T000000Z"],
    creator_meta: {
      display_name: "John Doe",
      email: "example@gmail.com",
      id: "123",
    },
    attendees_meta: [
      {
        display_name: "John Doe",
        email: "example@hotmail.com",
        rsvp_status: "accepted",
        rsvp_comment: "I'll be there",
        is_optional: false,
        is_event_organizer: true,
        additional_guests: 0,
        provider_meta: {},
      },
    ],
  });

EdgeQL query:

WITH
  __param__title := <std::str>$title,
  __param__recurrence := <array<std::str>>$recurrence,
  __param__creator_meta := <tuple<display_name: std::str, email: std::str, id: std::str>>$creator_meta,
  __param__attendees_meta := <array<tuple<display_name: std::str, email: std::str, rsvp_status: std::str, rsvp_comment: std::str, is_optional: std::bool, is_event_organizer: std::bool, additional_guests: std::int64, provider_meta: std::json>>>$attendees_meta
SELECT (INSERT default::Meeting {
  title := __param__title,
  recurrence := std::array_unpack(__param__recurrence),
  creator_meta := __param__creator_meta,
  attendees_meta := std::array_unpack(__param__attendees_meta)
})

Error:

error: Uncaught InternalServerError: cannot cast type record to edgedbpub."ead3bd00-2258-11ee-9477-9570e39cc69a_t"
    const err = new errorType(message);
@msullivan msullivan self-assigned this Aug 25, 2023
@msullivan msullivan changed the title InternalServerError: cannot cast type record to edgedbpub."ead3bd00-2258-11ee-9477-9570e39cc69a_t" Named tuple params whose types also appear in the schema don't work Aug 26, 2023
@msullivan
Copy link
Member

With the schema

 type Test {                                                              
    tup -> tuple<test: str>                                               
 }  

we get basically that error with

WITH
  p := <tuple<test: str>>$0
insert Test { tup := p };

With

WITH
  p := <tuple<test: str>>$0
select p

we get record type has not been registered

and with

select <tuple<test: str>>$0

we get could not identify column "test" in record data type

msullivan added a commit that referenced this issue Aug 26, 2023
The tuple argument decoder code simply ignores whether a tuple is
named, figuring that named tuples and unnamed tuples have the same
representation in the generated SQL, so why bother. (It was called out
as a "HACK" in the comments.)

But they only have the same representation when they are represented
as a `record`. If the tuple type appears in the schema, it gets
represented as a named composite type and we no longer have the right
representation.

Just do it right. Fixes #5789.
msullivan added a commit that referenced this issue Aug 30, 2023
The tuple argument decoder code simply ignores whether a tuple is
named, figuring that named tuples and unnamed tuples have the same
representation in the generated SQL, so why bother. (It was called out
as a "HACK" in the comments.)

But they only have the same representation when they are represented
as a `record`. If the tuple type appears in the schema, it gets
represented as a named composite type and we no longer have the right
representation.

Just do it right. Fixes #5789.
msullivan added a commit that referenced this issue Sep 2, 2023
The tuple argument decoder code simply ignores whether a tuple is
named, figuring that named tuples and unnamed tuples have the same
representation in the generated SQL, so why bother. (It was called out
as a "HACK" in the comments.)

But they only have the same representation when they are represented
as a `record`. If the tuple type appears in the schema, it gets
represented as a named composite type and we no longer have the right
representation.

Just do it right. Fixes #5789.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants