Skip to content

mix ash.codegen --check, fails #841

Description

@Straffern

Code of Conduct

  • I agree to follow this project's Code of Conduct

AI Policy

  • I agree to follow this project's AI Policy, or I agree that AI was not used while creating this issue.

Versions

ash_postgres: 2.11.0
ash: 3.31.3
Elixir: 1.20.1
Erlang/OTP: 28.5.0.2

Operating system

NixOS, Linux x86_64

Current Behavior

mix ash.codegen --check raises an internal error when a Resource has multiple removed attributes and multiple added attributes.

In this case, _dev migrations also remain. The command should report the existing _dev migration error. It instead crashes before it reaches that check:

** (RuntimeError) Could not get matching name after 3 attempts.

Relevant call stack:

Mix.Tasks.Ash.Codegen.run/1
  AshPostgres.DataLayer.codegen/1
    Mix.Tasks.AshPostgres.GenerateMigrations.run/1
      AshPostgres.MigrationGenerator.generate/2
        create_migrations/5
          fetch_operations/2
            do_fetch_operations/5
              attribute_operations/4
                resolve_renames/4
                  renaming?/3
                    yes?/2
                  get_new_attribute/3
                    prompt/2

In --check mode, yes?/2 returns true, while prompt/2 returns "response".

The generator therefore confirms that a removed attribute is a rename, but then cannot find an added attribute named "response". It retries three times and raises.

The _dev migration check occurs after operation and rename inference, so the command never reaches this intended message:

Codegen check failed.

You have migrations remaining that were generated with the --dev flag.

Run `mix ash.codegen <name>` to remove the dev migrations and replace them
with production-ready migrations.

### Reproduction


1. Create a Resource with these persisted attributes:

```text
old_a
old_b
old_c
old_d
  1. Generate a production-ready migration and snapshot:
mix ash.codegen initial_attributes
mix ash.migrate
  1. Replace those attributes with:
new_a
new_b
  1. Generate development codegen:
mix ash.codegen --dev
mix ash.migrate
  1. Run the automated check:
mix ash.codegen --check

The command deterministically raises:

Could not get matching name after 3 attempts.

The relevant state is:

attributes_to_remove = [old_a, old_b, old_c, old_d]
attributes_to_add    = [new_a, new_b]
check                = true
dev                  = false

Expected Behavior

  • When _dev migrations remain, it should report the existing _dev migration message.
  • For ambiguous changes without _dev migrations, it should report pending codegen without inventing a rename.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions