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

Ecto.Migration.index/3 silently mishandles multiple :where clauses #2690

Closed
nathanl opened this issue Sep 18, 2018 · 2 comments
Closed

Ecto.Migration.index/3 silently mishandles multiple :where clauses #2690

nathanl opened this issue Sep 18, 2018 · 2 comments

Comments

@nathanl
Copy link
Contributor

nathanl commented Sep 18, 2018

Environment

  • Elixir version (elixir -v): Elixir 1.7.1 (compiled with Erlang/OTP 21)
  • Database and version (PostgreSQL 9.4, MongoDB 3.2, etc.): PostgreSQL 10.2
  • Ecto version (mix deps): 2.2.10
  • Database adapter and version (mix deps): Postgrex 0.13.5
  • Operating system: MacOS High Sierra (10.13.6)

Problem

Ecto.Query.from allows multiple where: clauses. So it seems natural to use multiple where: clauses when creating an index with Ecto.Migration. However, doing so fails in a surprising way.

Current behavior

This statement:

    create(
      index(
        "seasons",
        :team_id,
        where: "started_at is not null",
        where: "ended_at is null",
        unique: true,
        name: "only_one_active_season_per_team"
      )
    )

...creates an index where only the second where: clause is used.

Expected behavior

Either index/3 should combine all where: clauses using AND, or it should raise an error when multiple where: clauses are given, suggesting that the user combine them.

@nathanl nathanl changed the title # Ecto.Migration.index/3 silently mishandles multiple :where clauses Ecto.Migration.index/3 silently mishandles multiple :where clauses Sep 18, 2018
@josevalim
Copy link
Member

josevalim commented Sep 18, 2018

Given those are strings and not query expressions, I think we can detect and raise then. PR please? :)

@nathanl
Copy link
Contributor Author

nathanl commented Sep 18, 2018

I'll try to make a PR for this in the next week or two.

josevalim added a commit that referenced this issue Sep 21, 2018
Because multiple `where:` keywords are supported by Ecto.Query, users
may provide multiple `where:` keywords when declaring a partial index.
However, this is not supported.

Previously, this would fail in a surprising way: the final `where:`
would be used and the other discarded. Now we raise an error, explaining
that these clauses should be combined into a single string.

Fixes #2690
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

No branches or pull requests

2 participants