ecto_sqlite3 icon indicating copy to clipboard operation
ecto_sqlite3 copied to clipboard

Implement Structure.dump_cmd/3

Open maennchen opened this issue 2 years ago • 22 comments

See https://github.com/elixir-ecto/ecto_sql/pull/423

  • [x] TODO: Change mix.exs back to released versions.

maennchen avatar Jul 01 '22 13:07 maennchen

I think the CI failure is not caused by this change.

maennchen avatar Jul 01 '22 13:07 maennchen

Thank you @maennchen I saw the PR for the other adapters. I'll get this rectified and this should be good to go.

warmwaffles avatar Jul 01 '22 14:07 warmwaffles

@maennchen try updating / rebasing this branch off of main. This was recently merged https://github.com/elixir-sqlite/ecto_sqlite3/pull/80

warmwaffles avatar Jul 01 '22 18:07 warmwaffles

@warmwaffles There is another issue. An insert_all integration test was added that uses select statements for values and it doesn't seem like your adapter supports that. The insert_select tag was missed but it's been fixed and merged into Ecto: https://github.com/elixir-ecto/ecto/pull/3942.

greg-rychlewski avatar Jul 01 '22 18:07 greg-rychlewski

There are two other failures:

  • Stacktraces were added to logging and the test didn't take into account that adapters like yours will have their integration tests nested under the deps directory. This has been fixed and merged https://github.com/elixir-ecto/ecto_sql/pull/426.
  • There is a failure for a new json test that was added after your version of Ecto: https://github.com/elixir-ecto/ecto/blame/master/integration_test/cases/type.exs#L321. What's happening is the values inside the meta map are not typed and when the driver returns 1 for meta["enabled"], your loaders don't detect that this is actually a boolean field and needs to be casted to true.

For the second issue, the only thing that comes to mind is to document that users should explicitly set the type in these situations:

TestRepo.one(from o in Order, select: type(o.meta["enabled"], :boolean))

instead of

TestRepo.one(from o in Order, select: o.meta["enabled"])

and then I guess there are two options for the tests:

  1. You skip all the json_extract_path tests and implement custom versions of them for your adapter
  2. Ecto has 2 versions of these tests, one of them using type/2 and the other one not. And the one that doesn't has a tag for you to skip.

Probably number 1 is better, because this is a super specific thing for sqlite? But let me know if you have a different idea.

greg-rychlewski avatar Jul 01 '22 19:07 greg-rychlewski

@warmwaffles I've rebased onto main. There's however still a few problems left as @greg-rychlewski noticed.

maennchen avatar Jul 02 '22 09:07 maennchen

Probably number 1 is better, because this is a super specific thing for sqlite? But let me know if you have a different idea.

This is probably a better idea to do.

It's probably okay to merge this into main and then follow up with tests. I am unsure why this PR doesn't have github actions running for it.

warmwaffles avatar Jul 05 '22 02:07 warmwaffles

I haven't forgotten about this, just haven't had time to dig in more.

warmwaffles avatar Jul 11 '22 14:07 warmwaffles

I think the actions are only running the first time the PR is opened because of this

pull_request:
    types:
      - opened

I think you need the synchronize activity for it to trigger on new commits.

greg-rychlewski avatar Jul 15 '22 01:07 greg-rychlewski

@maennchen would you mind rebasing off of the latest main branch? I want to see if the workflow change I made gets picked up and kicks off.

warmwaffles avatar Jul 15 '22 03:07 warmwaffles

@warmwaffles Rebased. Tests seem to be running :+1:

maennchen avatar Jul 15 '22 11:07 maennchen

Excellent, thanks @greg-rychlewski for pointing out that I had that types section.

warmwaffles avatar Jul 15 '22 13:07 warmwaffles

btw failed integration tests 1 and 3 can be fixed by updating to the latest commit on ecto/ecto_sql:

https://github.com/elixir-ecto/ecto/pull/3942 https://github.com/elixir-ecto/ecto_sql/pull/426

greg-rychlewski avatar Jul 16 '22 01:07 greg-rychlewski

@greg-rychlewski Updated

maennchen avatar Jul 17 '22 09:07 maennchen

@maennchen I sent a PR to your fork to fix the broken unit tests. the planner now returns the cast and dump version of the parameters and it was causing a match error.

greg-rychlewski avatar Jul 17 '22 13:07 greg-rychlewski

@maennchen if you rebase on master the tests should all pass now

greg-rychlewski avatar Aug 04 '22 15:08 greg-rychlewski

@greg-rychlewski Still seems to error, unfortunately.

maennchen avatar Aug 05 '22 08:08 maennchen

@maennchen oh it looks like the PR I sent you was reverted: https://github.com/maennchen/ecto_sqlite3/pull/1/files. if that change is re-implemented it should all pass

greg-rychlewski avatar Aug 05 '22 12:08 greg-rychlewski

@greg-rychlewski Oops, I rebased away your commit. I've brought it back.

maennchen avatar Aug 05 '22 13:08 maennchen

After the update, the following test breaks:

== Compilation error in file integration_test/json_test.exs ==
** (KeyError) key :meta not found
    expanding struct: Ecto.Integration.Order.__struct__/1
    integration_test/json_test.exs:10: Ecto.Integration.JsonTest."test json_extract_path with primitive values"/1

EDIT

The error above was fixed with https://github.com/elixir-sqlite/ecto_sqlite3/pull/79/commits/3d8d9cacdd506a3aae879b5ba181aa0f95b0a9f1

maennchen avatar Sep 28 '22 08:09 maennchen

After the fix 4 tests still fail with similar errors:

  * test query select selected_as/2 with having (3.9ms) [L#1608]

  1) test query select selected_as/2 with having (Ecto.Integration.RepoTest)
     deps/ecto/integration_test/cases/repo.exs:1608
     ** (Ecto.QueryError) unsupported expression :min_visits in query:
     
     from p0 in Ecto.Integration.Post,
       group_by: [p0.posted],
       having: selected_as(:min_visits) > 0,
       or_having: not (selected_as(:min_visits) > 0),
       order_by: [asc: p0.posted],
       select: %{posted: p0.posted, min_visits: selected_as(min(coalesce(p0.visits, 0)), :min_visits)}
     
     code: |> TestRepo.all()
     stacktrace:
       (ecto_sqlite3 0.8.1) lib/ecto/adapters/sqlite3/connection.ex:1403: Ecto.Adapters.SQLite3.Connection.expr/3
       (ecto_sqlite3 0.8.1) lib/ecto/adapters/sqlite3/connection.ex:1806: Ecto.Adapters.SQLite3.Connection.intersperse_map/4
       (ecto_sqlite3 0.8.1) lib/ecto/adapters/sqlite3/connection.ex:1356: Ecto.Adapters.SQLite3.Connection.expr/3
       (ecto_sqlite3 0.8.1) lib/ecto/adapters/sqlite3/connection.ex:1353: Ecto.Adapters.SQLite3.Connection.expr/3
       (ecto_sqlite3 0.8.1) lib/ecto/adapters/sqlite3/connection.ex:1172: Ecto.Adapters.SQLite3.Connection.paren_expr/3
       (ecto_sqlite3 0.8.1) lib/ecto/adapters/sqlite3/connection.ex:1143: Ecto.Adapters.SQLite3.Connection.boolean/4
       (ecto_sqlite3 0.8.1) lib/ecto/adapters/sqlite3/connection.ex:171: Ecto.Adapters.SQLite3.Connection.all/2
       (ecto_sqlite3 0.8.1) lib/ecto/adapters/sqlite3.ex:176: Ecto.Adapters.SQLite3.prepare/2
       (ecto 3.9.0) lib/ecto/query/planner.ex:182: Ecto.Query.Planner.query_without_cache/4
       (ecto 3.9.0) lib/ecto/query/planner.ex:152: Ecto.Query.Planner.query_prepare/6
       (ecto 3.9.0) lib/ecto/query/planner.ex:127: Ecto.Query.Planner.query_with_cache/8
       (ecto 3.9.0) lib/ecto/repo/queryable.ex:211: Ecto.Repo.Queryable.execute/4
       (ecto 3.9.0) lib/ecto/repo/queryable.ex:19: Ecto.Repo.Queryable.all/3
       deps/ecto/integration_test/cases/repo.exs:1624: (test)

maennchen avatar Sep 28 '22 08:09 maennchen

@maennchen You can add these tags to the ignore list for the integration tests:

:selected_as_with_group_by :selected_as_with_order_by :selected_as_with_order_by_expression :selected_as_with_having

greg-rychlewski avatar Sep 28 '22 13:09 greg-rychlewski

@maennchen I believe if you drop the changes made to the mix.lock the conflict should be resolved.

warmwaffles avatar Nov 29 '22 03:11 warmwaffles

@warmwaffles I've rebased and it seems the tests are failing again.

I've spent more time now rebasing this PR than writing it. I would welcome it if a maintainer makes sure that this PR is incorporated in a way that actually works.

maennchen avatar Nov 29 '22 10:11 maennchen

@maennchen I'll see what I can do and try to retain your original authorship. Definitely want to keep your contributions attached.

warmwaffles avatar Nov 29 '22 15:11 warmwaffles

Thanks a ton @maennchen for implementing this. It's been merged and deployed under v0.9.0

warmwaffles avatar Dec 01 '22 05:12 warmwaffles