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

Ash.Type.generator/1 should return DataStream #8

Merged
merged 1 commit into from
Jun 20, 2024

Conversation

hwuethrich
Copy link
Contributor

While using Ash.Generator.seed/1 I got the following error:

** (ArgumentError) expected a generator, which can be a %StreamData{} struct, an atom, or a tuple with generators in it, but got:

  "col_02wsdmCe7p61fA5nVLcFYJ"

If you want to use a term as a "constant" generator, wrap it in a call to StreamData.constant/1 instead.

I noticed that the callback Ash.Type.generator/1 should actually return an Enumerable instead of a single value:

@callback generator(constraints) :: Enumerable.t()

To fix the issue, I renamed the existing generator/1 to generate/1 and implemented the generator as expected (using Ash.Type.UUID as reference).

Heads-up: I also tried to add a test for the generator function by using Ash.Generator.seed!/1 in the existing tests (which failed, possibly because of an unrelated Ash bug). When I updated all the dependencies, I noticed that ash_postgres v2.0.10 will break your tests (v2.0.9 is fine):

  6) test AshUUID.PrefixedV4 testing oranges (AshUUIDTest)
     test/ash_uuid_test.exs:140
     ** (Ash.Error.Unknown) Unknown Error

     * ** (Postgrex.Error) ERROR 22P02 (invalid_text_representation) invalid input syntax for type uuid: "orange-smoothie_3ZhwNimx2NuodIDMu2xmwo". If you are trying to query a JSON field, the parameter may need to be interpolated. Instead of

         p.json["field"] != "value"

     do

         p.json["field"] != ^"value"


         query: SELECT o0."id", o0."inserted_at", o0."orange_smoothie_id" FROM "oranges" AS o0 WHERE (o0."orange_smoothie_id"::uuid IN ('orange-smoothie_3ZhwNimx2NuodIDMu2xmwo'))
         at oranges
       (ecto_sql 3.11.3) lib/ecto/adapters/sql.ex:1054: Ecto.Adapters.SQL.raise_sql_call_error/1
       (ecto_sql 3.11.3) lib/ecto/adapters/sql.ex:952: Ecto.Adapters.SQL.execute/6
       (ecto 3.11.2) lib/ecto/repo/queryable.ex:232: Ecto.Repo.Queryable.execute/4
       (ecto 3.11.2) lib/ecto/repo/queryable.ex:19: Ecto.Repo.Queryable.all/3
       (ash_postgres 2.0.10) lib/data_layer.ex:758: anonymous fn/3 in AshPostgres.DataLayer.run_query/2
       (ash_postgres 2.0.10) lib/data_layer.ex:756: AshPostgres.DataLayer.run_query/2
       (ash 3.0.15) lib/ash/actions/read/read.ex:2423: Ash.Actions.Read.run_query/4
       (ash 3.0.15) lib/ash/actions/read/read.ex:447: anonymous fn/5 in Ash.Actions.Read.do_read/4
       (ash 3.0.15) lib/ash/actions/read/read.ex:777: Ash.Actions.Read.maybe_in_transaction/3
       (ash 3.0.15) lib/ash/actions/read/read.ex:248: Ash.Actions.Read.do_run/3
       (ash 3.0.15) lib/ash/actions/read/read.ex:66: anonymous fn/3 in Ash.Actions.Read.run/3

@moissela
Copy link
Member

Hi @hwuethrich
I'll merge this as soon as #9 is resolved.

The current generator was clearly wrong until now 🙈

Thank you for notice this bug, opening the PR and your contribution!

@hwuethrich
Copy link
Contributor Author

@moissela It looks like the other issue was caused by a bug in ash_postgres 2.0.9

@moissela moissela merged commit e5e1066 into zoonect-oss:main Jun 20, 2024
11 of 12 checks passed
@moissela
Copy link
Member

Thanks @hwuethrich for your contribution 🚀

I'll release new AshUUID version to hex shortly!

@moissela
Copy link
Member

Released!

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

Successfully merging this pull request may close these issues.

2 participants