hasura / graphql-engine

Blazing fast, instant realtime GraphQL APIs on your DB with fine grained access control, also trigger webhooks on database events.
https://hasura.io
Apache License 2.0
31.13k stars 2.76k forks source link

Enum Not Added To Schema #3759

Closed jcmoore0 closed 3 years ago

jcmoore0 commented 4 years ago

Problem: Enums are not updating v1.1.0-beta.2

Details/ Steps to Reproduce:

New Enum

  1. Change table to enum Go to Docs -> no enum found for table

Change Enum

  1. Add row to existing enum table.
  2. Press 'reload enum values' Go to Docs -> no additional enum found for table
lexi-lambda commented 4 years ago

Thanks for the report! I think I know what’s causing this—we added some additional caching to the metadata reloading process, and it’s being a little too aggressive for enum tables (the enum values aren’t technically part of the metadata, so it thinks the table “didn’t change” and skips reprocessing it). The fix should be easy.

jcmoore0 commented 4 years ago

Hi @lexi-lambda - I am still having issues with the new v1.1.0-beta.3 release.

'reload enum values' - intermittently works ~20% time 'make table an enum' - doesn't work after many tries

Thanks for the help. Best regards,

lexi-lambda commented 4 years ago

@jcmoore0 Could you say more about what you’re seeing? Are you getting any errors, or is there just no effect whatsoever?

jcmoore0 commented 4 years ago

@lexi-lambda - I don't get any errors. It's just not changing the schema. Thanks, John

jcmoore0 commented 4 years ago

Hi @lexi-lambda - I just realized the schema will not include enum until a relationship is created to an enum table.

Update: 'reload enum values' - intermittently works ~20% time -> restart server as a work around 'make table an enum' - works -> need to create a relationship to the enum table first

Thanks for the help. Best regards,

mirzap commented 4 years ago

Still a problem in v1.2.0-beta.2 After adding a new value to the enum table, I reloaded enum values multiple times but still metadata wasn't updated. I get following err:

graphql-engine_1  | Spock Error while handling ["v1","query"]: expected one of the values "en", "de" for type "settings_locales", given "fr"

fr is a new value in enum table.

Restarting hasura server helped.

fbrbovic commented 4 years ago

I am experiencing the same problem, no matter how many times I reload it, new values don't show up. Will try restarting the server.

lexi-lambda commented 4 years ago

It would be very helpful if you should share a schema that reproduces the issue! Otherwise it’s hard to know what’s going on.

jcmoore0 commented 4 years ago

Hi @lexi-lambda - 'Reload enum values' doesn't update schema. It's not super urgent since there is a workaround by restarting the server.

I just ran a simple test and included migrations here: https://github.com/jcmoore0/hasura_enum

Let me know if you need something else.

Best regards,

lexi-lambda commented 4 years ago

Thanks, that’s extremely helpful! I can’t promise that we’ll look into it immediately, but I’ll definitely make sure it gets looked at in the near future.

mirzap commented 4 years ago

This seems to be fixed with latest release (v1.2.0-beta.3) After clicking "reload enum values" metadata is updated correctly and there's no need to restart hasura server anymore.

Thanks! 🙏

jcmoore0 commented 4 years ago

Confirmed fix. Thanks, great job.

kurt-o-sys commented 4 years ago

It's still not updated here, I'm running hasura 1.2.1. After adding new values, I can't use the new values in insert operations. If I query the enum field using the graphiql/api-explorer, the new values are there.

Switching off and 'Set table as enum' does reload the values.

image

In any case, if there's a button 'reload values, it should work :).

BlueSeph28 commented 4 years ago

The same happens here! Hasura 1.1.1, I insert some values, click to "reload values" and doens't work

I do the "switching off and 'Set table as enum'" workaround and it works!

pronevich commented 4 years ago

v1.2.2 the same issue. @marionschleifer it's more than half year for pretty serious bug )

nomocas commented 4 years ago

Hi All, Same issue on Hasura 1.3.

andycmaj commented 4 years ago

i believe that might be what's causing this as well:

enum bug

running same query multiple times (with an enum_userOnboardingStatus_enum_comparison_exp) returns failure about 50% of the time.

this was after a migration that added a new enum value.

i force-restarted all of my hasura instances, and this problem went away completely. so yes. seems like caching is the issue.

this is on 1.3.0 running 2 dynos on heroku.

Nomad-Go commented 4 years ago

Still having this problem on version 1.3.2 had to "force new deployment" on my AWS ECS Service. I tried both reloading the enum table and reloading all metadata.

MarkNBroadhead commented 4 years ago

Having issue on Hasura 1.3.2. Brand new docker container & database, schema not updating when new enums are added to database table.

ghost commented 4 years ago

This is happening to me on Hasura Cloud. I literally can't update my application because of this bug.

lexi-lambda commented 4 years ago

I finally got to looking into this, and I’m afraid to say I still cannot reproduce this on my machine. :slightly_frowning_face: I tried following the steps in https://github.com/hasura/graphql-engine/issues/3759#issuecomment-603013180 a few times against graphql-engine v1.3.2, but every time I pressed “Reload Enum Values,” I saw the schema immediately update.

This is frustrating, because obviously the issue is happening for several people. I am definitely not denying that! But I have no idea what could possibly be going wrong, and without being able to reproduce the problem, I am not sure how to proceed.

Here are the full details of my environment:

If anyone can provide an environment that consistently reproduces this issue, I’d be much obliged. In the meantime, I’m afraid I’m at something of a loss.

pronevich commented 4 years ago

Hi, @lexi-lambda here is the reproduction:

  1. I created new project in Hasura Cloud.
  2. Created in console SQL:
    
    CREATE TABLE test_enum (
    val text PRIMARY KEY,
    description text
    );

INSERT INTO test_enum (val, description) VALUES ('FIRST', 'First test enum val'), ('SECOND', 'Second test enum val');

3. Created in console SQL. type - ref to test_enum
```sql
CREATE TABLE use_enum (
  id int GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
  type text NOT NULL REFERENCES test_enum
);

INSERT INTO use_enum (type) VALUES
  ('FIRST'),
  ('SECOND');
  1. Set table as enum
  2. Update enum value FIRST to FIRST_UPD
  3. Reload enum values image
  4. Test if enum value was changed in schema - NO image
lexi-lambda commented 4 years ago

Good news: with the help of both the comments on this issue and some investigation by a couple other folks on the team, I finally managed to consistently reproduce the issue on my machine. PR #6027 has the fix, which should hopefully finally resolve this problem for good once merged. Thank you all for your patience!

janosroden commented 3 years ago

For hasura newbies like me: add Foreign key below columns, not Relation.

willyxiao commented 3 years ago

Hi @lexi-lambda is there a workaround for this for hasura v1.3.2?

osdiab commented 2 years ago

Just registering that this is still happening to my project on version 2.1.0-beta.3 CLI / v2.1.0 gql engine. If there doesn't exist a foreign key to an enum table, then the enum won't be generated in GQL (and therefore graphql-codegen also won't create the enum in my TypeScript project). This is easily worked around by just making a dummy table that just contains a foreign key to the enum table, then immediately removing that table (by running the down migration for instance) to de-clutter the database; but that's ugly and counterintuitive, so would prefer if the enum just got created reliably!

Also tried editing the enum variables after doing the above workaround - it does update without needing to re-introduce the foreign key. So only seems to be an issue when creating the enum table for the first time. nevermind seems to have disappeared when i removed that table :( kinda sucks but i'll just be keeping a dummy table.

ofilipowicz commented 2 years ago

Hey @lexi-lambda, it's not working on v2.2.1. I tried reloading enums, disabling and enabling enum on a table. Whatever I do, it just isn't added as enum to scheme.

It only works if there is a FK on other table used as @osdiab mentioned.

OlivierBS commented 1 year ago

This is still an issue in v2.16.1, the only fix seems to be to create a seperate dummy table with a foreign key to trick hasura into generating the enum type.

ingridkindem commented 1 year ago

Tried reloading metadata, but just got errors. Restarting the server did the trick for me

hpsmatheus commented 1 year ago

Still getting this error on v2.25.1 @lexi-lambda

ts-hems commented 1 month ago

Hi there,

I'm experiencing the same issue in version 2.42.0. It was working with the previous added enum, but when we added a new enum in a different schema, it's not being picked up and is causing an error in the fetch query.

Is there any solution? @hpsmatheus, has this been resolved yet?

Thank you Hems Patel Tracksuit