aesmail / aesmail/kaffy

[BUG] Models without primary key cause 500

Abierto
#333 0 comentarios 0 reacciones 1 asignado Reclamado por @aesmail Ver en GitHub
bug
Lenguaje dominante
Elixir
Estrellas
1.4k
Forks
171
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

**Versions Used**
Kaffy: 0.10.3
Phoenix: 1.7.10
Elixir:
```
Erlang/OTP 27 [erts-15.2] [source] [64-bit] [smp:10:10] [ds:10:10:10] [async-threads:1] [jit]

Elixir 1.18.2 (compiled with Erlang/OTP 27)
```
**What's actually happening?**

We have the following schema:

```
@primary_key false
schema "auth_identity_provider" do
field :id, :string
field :name, :string

timestamps(type: :utc_datetime)
end
```

We also have this model defined as a resource for kaffy:

```
def create_resources(_conn) do
[
user_management: [
name: "User Management",
resources: [
identity_provider: [schema: App.Models.Auth.IdentityProvider]
]
]
]
end
```

Navigating to the list page of this model, I get a 500 error:

```
[error] #PID<0.11416.0> running Phoenix.Endpoint.SyncCodeReloadPlug (connection #PID<0.11410.0>, stream id 1) terminated
Server: localhost:4000 (http)
Request: GET /app/admin_tool/user_management/identity_provider
** (exit) an exception was raised:
** (MatchError) no match of right hand side value: []
(kaffy 0.10.3) lib/kaffy/resource_admin.ex:165: Kaffy.ResourceAdmin.ordering/1
(kaffy 0.10.3) lib/kaffy/resource_query.ex:43: Kaffy.ResourceQuery.get_ordering/2
(kaffy 0.10.3) lib/kaffy/resource_query.ex:12: Kaffy.ResourceQuery.list_resource/3
(kaffy 0.10.3) lib/kaffy_web/controllers/resource_controller.ex:69: KaffyWeb.ResourceController.index/2
(kaffy 0.10.3) lib/kaffy_web/controllers/resource_controller.ex:1: KaffyWeb.ResourceController.action/2
(kaffy 0.10.3) lib/kaffy_web/controllers/resource_controller.ex:1: KaffyWeb.ResourceController.phoenix_controller_pipeline/2
(phoenix 1.7.20) lib/phoenix/router.ex:484: Phoenix.Router.__call__/5
(workera_webapps 0.1.0) lib/workera_webapps_web/endpoint.ex:1: WorkeraWebappsWeb.Endpoint.plug_builder_call/2
(workera_webapps 0.1.0) deps/plug/lib/plug/debugger.ex:155: WorkeraWebappsWeb.Endpoint."call (overridable 3)"/2
(workera_webapps 0.1.0) lib/workera_webapps_web/endpoint.ex:1: WorkeraWebappsWeb.Endpoint.call/2
(phoenix 1.7.20) lib/phoenix/endpoint/sync_code_reload_plug.ex:22: Phoenix.Endpoint.SyncCodeReloadPlug.do_call/4
(plug_cowboy 2.7.3) lib/plug/cowboy/handler.ex:11: Plug.Cowboy.Handler.init/2
(cowboy 2.12.0) /Users/sebastian/workspace/workera/workera-dev-workspace/src/workera_webapps/deps/cowboy/src/cowboy_handler.erl:37: :cowboy_handler.execute/2
(cowboy 2.12.0) /Users/sebastian/workspace/workera/workera-dev-workspace/src/workera_webapps/deps/cowboy/src/cowboy_stream_h.erl:306: :cowboy_stream_h.execute/3
(cowboy 2.12.0) /Users/sebastian/workspace/workera/workera-dev-workspace/src/workera_webapps/deps/cowboy/src/cowboy_stream_h.erl:295: :cowboy_stream_h.request_process/3
(stdlib 6.2) proc_lib.erl:329: :proc_lib.init_p_do_apply/3 -
```

This happens even if I create an Admin module and specify the `ordering/1` function.

**What should happen instead?**

Kaffy should expose a way to work with models that do not have a primary key. My immediate idea would be to have a function in the admin model that let's you define which field to use as the "primary key" in case there is none defined on the model.

**Screenshots**
If applicable, add screenshots to help explain your problem.

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.