GenieFramework / GenieFramework/SearchLight.jl
Callbacks API
- Dominant language
- Julia
- Stars
- 149
- Forks
- 18
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
If callback fields are specified in the model, entries cannot be saved to the database. The `save!` function expects the callback fields of the struct as columns in the database table.
**Error stacktrace**
```
[ Info: 2020-12-01 19:17:36 Do something before saving
[ Info: 2020-12-01 19:17:36 INSERT INTO callbacks ( "title", "indicator", "created_at", "before_save", "after_save" ) VALUES ( E'testing', true, E'2020-12-01T19:17:36.376', E'#4', E'#5' ) RETURNING id
[error | LibPQ]: UndefinedColumn: ERROR: column "before_save" of relation "callbacks" does not exist
LINE 1: ...O callbacks ( "title", "indicator", "created_at", "before_sa...
^
ERROR: UndefinedColumn: ERROR: column "before_save" of relation "callbacks" does not exist
```
**To reproduce**
1. Create a model containing callbacks, e.g.
```julia
@kwdef mutable struct Callback <: AbstractModel
id::DbId = DbId()
title::String = ""
indicator::Bool = true
created_at::String = string(Dates.now())
# callbacks
before_save::Function = (m::Callback) -> begin
@info "Do something before saving"
end
after_save::Function = (m::Callback) -> begin
@info "Do something after saving"
end
end
```
2. Save entry to database
```julia
julia> Callback(title = "testing") |> save!
```
This will result in the above `UndefinedColumn` error.
**Expected behavior**
The expected behaviour is to ignore the callback fields (`before_save` and `after_save`) of the `struct` when creating entries in the database.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.