Question on top of Question fails with weird `ERROR: column does not exist`

This issue is a bit tangled and I am not sure where to start looking at to work on a reproducer, so please bear with me.

I have a Question that originates from joining a raw table with a Model, which works perfectly fine. The beginning of the underlying SQL is

SELECT
  "Question 34"."Orchest Cloud Users__email" AS "Question 34__Orchest Cloud Users__email"
  , sum("analytics"."events_per_day"."count") AS "sum"
FROM "analytics"."events_per_day"
LEFT JOIN (...)

It's interesting though that there are references to a certain Question 34 that corresponds to the Model.

However, if I create another Question on top of that one, I get the following error:

ERROR: column source.Question 34__email does not exist Position: 124

which probably comes from the fact that the generated SQL looks incorrect:

SELECT
  "source"."Question 34__email" AS "Question 34__email"
  , "source"."sum" AS "sum"
FROM (
  SELECT
    "Question 34"."Orchest Cloud Users__email" AS "Question 34__Orchest Cloud Users__email"
    , sum("analytics"."events_per_day"."count") AS "sum"
  FROM "analytics"."events_per_day"
  LEFT JOIN (...)

I didn't change any metadata along the way. I see there are several potentially relevant issues (gh-23248, gh-20624, gh-23019, gh-22518) but I'm wondering if someone could give a tip on how to more effectively debug this, or create a reproducer with Sample data or data created on the fly with SELECT statements.

Hi @juanlu_orchest
Looks like you're hitting this issue:
https://github.com/metabase/metabase/issues/22859 - upvote by clicking :+1: on the first post

1 Like