Hello,
I have a very strange behaviour with my program. When I start it for the first time, then it fails with an error message that is not very helpful. When I start it for the second time, then it completes without any problems. This happens always when I have a new Julia session. Therefore I think that it could be a problem with the compiler or with the scope of variables, the dependencies or other parts of the program.
The program runs always, even at first run, without any problems when I have it as a script and not as a module. I had to transform it to a module because of the PackageCompiler that I use to create an EXE file. However, it is no problem of the PackageCompiler because the problem occurs even when starting my program manually in VSCode.
My program has this structure:
module BlaApp
using Dates
using DataFrames
using Nettle
using ODBC
using Tables
using TOML
import DBInterface as dbi
import SMTPClient as smtp
function program_main()
# Here I have hundreds of lines of code. This is my program which works without any problems as a script.
df_1 = DBInterface.execute(conn_1, sql_query) |> DataFrame # At this line I get the error message at first run!
println("LZ: ", nrow(df_1)) # VSCode marks this line with a blue underscore and seems not to recognize the dataframe!
# More lines of code.
end
function julia_main()::Cint # The main function used to start the program. A must have because of PackageCompiler.
try
program_main() # This one fails. First run.
catch
program_main() # This one completees withouut any problems.
end
return 0
end
end
This is the error message when running the program for the first time:
ERROR:
Stacktrace:
[1] error(s::String)
@ Base .\error.jl:35
[2] iterate(x::ODBC.Cursor{false, false}, st::Int64)
@ ODBC C:\Users\miro.julia\packages\ODBC\9VZTC\src\dbinterface.jl:398
[3] iterate
@ C:\Users\miro.julia\packages\ODBC\9VZTC\src\dbinterface.jl:387 [inlined]
[4] iterate
@ .\iterators.jl:167 [inlined]
[5] iterate
@ .\iterators.jl:166 [inlined]
[6] buildcolumns(schema::Tables.Schema{(:BookingFachlicheID, :Export_id, :ChangedWhen), Tuple{Union{Missing, String}, Int32, Dates.DateTime}}, rowitr::ODBC.Cursor{false, false})
@ Tables C:\Users\miro.julia\packages\Tables\T7rHm\src\fallbacks.jl:139
[7] columns
@ C:\Users\miro.julia\packages\Tables\T7rHm\src\fallbacks.jl:256 [inlined]
[8] DataFrames.DataFrame(x::ODBC.Cursor{false, false}; copycols::Nothing)
@ DataFrames C:\Users\miro.julia\packages\DataFrames\LteEl\src\other\tables.jl:57
[9] DataFrame
@ C:\Users\miro.julia\packages\DataFrames\LteEl\src\other\tables.jl:48 [inlined]
[10] |>(x::ODBC.Cursor{false, false}, f::Type{DataFrames.DataFrame})
@ Base .\operators.jl:911
[11] program_main()
@ Main.BlaApp c:\JuliaWS\Bla\BlaApp\src\BlaApp.jl:133
[12] julia_main()
@ Main.BlaApp c:\JuliaWS\Bla\BlaApp\src\BlaApp.jl:235
[13] top-level scope
@ REPL[1]:1
The error message points to this line:
df_1 = DBInterface.execute(conn_1, sql_query) |> DataFrame
It is the only line in my program that uses this syntax “|> DataFrame” for converting the result of the DBInterface.execute, a cursor, to a DataFrame. But, as I mentioned, it works as a script always and when running the function in the module for the second time without any problems.
I already tried to do import DataFrames as df and referencing by df instead of using DataFrames, but it did not help.
I am using Julia version 1.8.3, DataFrames version 1.5.0 and Windows 10 64-Bit.
What is the problem?
Thanks for any answers in advance!
Kind regards,
Miroslav