Skip to content

Commit 134572a

Browse files
Fix validation when creating time series via API
1 parent 940a09c commit 134572a

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

src/PSRDatabaseSQLite/collection.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,15 @@ function _get_collection_time_series_files_tables(::SQLite.DB, collection_id::St
428428
return string(collection_id, "_time_series_files")
429429
end
430430

431+
function _dimensions_of_time_series_group(collection::Collection, group_id::String)
432+
time_series = collection.time_series
433+
for (_, time_series_attribute) in time_series
434+
if time_series_attribute.group_id == group_id
435+
return time_series_attribute.dimension_names
436+
end
437+
end
438+
end
439+
431440
function _validate_actions_on_foreign_key(
432441
collection_id::String,
433442
table_name::String,

src/PSRDatabaseSQLite/create.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ function create_element!(
210210
catch e
211211
@error """
212212
Error creating element in collection \"$collection_id\"
213-
error message: $(e.msg)
214213
"""
215214
rethrow(e)
216215
end

src/PSRDatabaseSQLite/validate.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,16 +364,21 @@ function _throw_if_data_does_not_match_group(
364364
df::DataFrame,
365365
)
366366
collection = _get_collection(db, collection_id)
367+
dimensions_of_group = _dimensions_of_time_series_group(collection, group)
367368
dimensions_in_df = []
368369
attributes_in_df = []
369370

370371
for column in names(df)
371372
if column in keys(collection.time_series)
372373
# should be an attribute
373374
push!(attributes_in_df, column)
374-
else
375+
elseif column in dimensions_of_group
375376
# should be a dimension
376377
push!(dimensions_in_df, column)
378+
else
379+
psr_database_sqlite_error(
380+
"Attribute \"$column\" is not an attribute or dimension of the time series group \"$group\".",
381+
)
377382
end
378383
end
379384

0 commit comments

Comments
 (0)