GenieFramework / GenieFramework/SearchLight.jl
"ERROR: UndefKeywordError: keyword argument _____ not assigned" when doing all(__)
- Dominant language
- Julia
- Stars
- 149
- Forks
- 18
- PR merge metrics
- No merged PRs in 30d
Description
Hello! I really am eager to see SearchLight become a fully-documented web framework for Julia, something the language desperately needs. The code looks very capable, it's just a challenge to find out how to use it correctly.
Anyway, here's the issue I'm having at the moment. I'm using SearchLight v2.2.1, but this also happened with v2.2.0.
I have a resource TTIntervals which defines the following struct and corresponding kwdef constructor:
```
@kwdef mutable struct TTInterval <: AbstractModel
id::DbId = DbId()
node_id::Int64
user_id::Int64
start_time::DateTime
#end_times can be nothing (aka NULL):
end_time::Union{DateTime,Nothing}=nothing
end
```
Here is the sql from `sqldump` that describes the resulting table in the database:
```
CREATE TABLE `ttintervals` (
`id` int NOT NULL AUTO_INCREMENT,
`node_id` int DEFAULT NULL,
`user_id` int DEFAULT NULL,
`start_time` datetime DEFAULT NULL,
`end_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `ttintervals__idx_node_id` (`node_id`),
KEY `ttintervals__idx_user_id` (`user_id`)
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
```
I have this data in the database added through SearchLight by making an instance of TTInterval and save!(ing) it:
```
mysql> select * from ttintervals;
+----+---------+---------+---------------------+---------------------+
| id | node_id | user_id | start_time | end_time |
+----+---------+---------+---------------------+---------------------+
| 1 | 1 | 1 | 2022-01-01 00:00:00 | 2023-01-01 00:00:00 |
| 2 | 1 | 1 | 2022-01-01 00:00:00 | 2023-01-01 00:00:00 |
| 3 | 1 | 1 | 2022-01-01 00:00:00 | 2023-01-01 00:00:00 |
| 4 | 1 | 1 | 2022-05-03 14:32:05 | 2023-01-01 00:00:00 |
| 5 | 1 | 1 | 2022-05-03 14:32:05 | 2023-01-01 00:00:00 |
| 6 | 1 | 1 | 2022-05-03 14:32:05 | 2023-01-01 00:00:00 |
| 7 | 1 | 1 | 2022-05-03 14:32:05 | NULL |
| 8 | 1 | 1 | 2022-05-03 14:32:05 | 2023-01-01 00:00:00 |
| 9 | 1 | 1 | 2022-05-03 14:32:05 | 2023-01-01 00:00:00 |
| 10 | 1 | 1 | 2022-05-03 14:32:05 | NULL |
| 11 | 1 | 1 | 2022-05-03 14:32:05 | NULL |
| 12 | 1 | 1 | 2022-05-03 14:32:05 | NULL |
+----+---------+---------+---------------------+---------------------+
12 rows in set (0.00 sec)
```
The issue comes when I try to retrieve the data. It doesn't matter of I do a find() or a all(), anything that tries to convert DataTables into objects results in the same error. Here it is:
```
julia> using SearchLight
julia> all(TTIntervals.TTInterval)
[ Info: 2022-05-22 01:19:18 SELECT `ttintervals`.`id` AS `ttintervals_id`, `ttintervals`.`node_id` AS `ttintervals_node_id`, `ttintervals`.`user_id` AS `ttintervals_user_id`, `ttintervals`.`start_time` AS `ttintervals_start_time`, `ttintervals`.`end_time` AS `ttintervals_end_time` FROM `ttintervals` ORDER BY ttintervals.id ASC
ERROR: UndefKeywordError: keyword argument node_id not assigned
Stacktrace:
[1] TTIntervals.TTInterval()
@ TTIntervals ./util.jl:453
[2] to_model(m::Type{TTIntervals.TTInterval}, row::DataFrames.DataFrameRow{DataFrames.DataFrame, DataFrames.Index}; skip_callbacks::Vector{Symbol})
@ SearchLight ~/.julia/packages/SearchLight/2kAM0/src/SearchLight.jl:493
[3] to_model
@ ~/.julia/packages/SearchLight/2kAM0/src/SearchLight.jl:492 [inlined]
[4] to_model!!
@ ~/.julia/packages/SearchLight/2kAM0/src/SearchLight.jl:572 [inlined]
[5] to_models(m::Type{TTIntervals.TTInterval}, df::DataFrames.DataFrame)
@ SearchLight ~/.julia/packages/SearchLight/2kAM0/src/SearchLight.jl:473
[6] find(m::Type{TTIntervals.TTInterval}, q::SQLQuery, j::Nothing) (repeats 2 times)
@ SearchLight ~/.julia/packages/SearchLight/2kAM0/src/SearchLight.jl:92
[7] #all#34
@ ~/.julia/packages/SearchLight/2kAM0/src/SearchLight.jl:179 [inlined]
[8] all(m::Type{TTIntervals.TTInterval})
@ SearchLight ~/.julia/packages/SearchLight/2kAM0/src/SearchLight.jl:179
[9] top-level scope
@ REPL[4]:1
```
The stack trace at [2] points to this code:
```
@ SearchLight ~/.julia/packages/SearchLight/2kAM0/src/SearchLight.jl:493
function to_model(m::Type{T}, row::DataFrames.DataFrameRow; skip_callbacks::Vector{Symbol} = Symbol[])::T where {T<:AbstractModel}
_m::T = try
-> m()
catch ex
isa(ex, MethodError) ? Base.invokelatest(m) : rethrow(ex)
end
```
It seems that SearchLight is trying to create an instance of the model without providing any kwargs at all and that's erroring out. It's in a try though so I'm not really sure why it's erroring out, but it is.
It seems like putting something in the DB and taking it out again is pretty normal stuff for an ORM, so I'm baffled that I would be the only one having this issue. Am I doing something dumb or is the package broken?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the failing all(TTIntervals.TTInterval) or find call and read SearchLight.jl around lines 473, 492-493, and 572, especially to_model and to_models. Reproduce the conversion using the shown TTInterval definition and database rows. Done means rows from the ttintervals table can be converted into TTInterval objects without the UndefKeywordError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia, mysql
- Domain
- backend, database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100