Fork me on GitHub
#sql
<
2021-02-25
>
mynomoto12:02:19

We have a project at work that uses hugsql with clojure.java.jdbc. To deploy in production we do AOT but last night we got a CompilerException:

CompilerException: Syntax error compiling at (hugsql/adapter/clojure_java_jdbc.clj:11:7).
...
RuntimeException: No such var: jdbc/db-do-prepared-return-keys
    at clojure.lang.Util.runtimeException(Util.java:221)
    at clojure.lang.Compiler.resolveIn(Compiler.java:7388)
    at clojure.lang.Compiler.resolve(Compiler.java:7358)
    at clojure.lang.Compiler.analyzeSymbol(Compiler.java:7319)
    at clojure.lang.Compiler.analyze(Compiler.java:6768)

mynomoto12:02:12

Has anyone seem that before or has any lead of how to debug this? A related question: should be a java class for each aot compiled clojure namespace? I looked at the uberjar but found the structure way different than I expected but that may be just my ignorance of what should be in there.

mynomoto12:02:22

The code is is production for a long time and we never saw that error before. What changed a couple of months ago is the addition of AOT.

hiredman17:02:08

aot compilation has a habit of shaking and weird unexpected things in your code base

hiredman17:02:41

two places to start on your error would be making sure you don't have any stale class files laying around (class files generate from previous aots), and checking your dependency tree to see if you are somehow pulling in a different version of clojure.java.jdbc than expected

hiredman17:02:00

did you get that error compiling or when running?

mynomoto18:02:59

@hiredman thanks for taking the time to respond. It happened when running. The uberjar is built on a ci server so no stale classes should be possible. I will check the dependency tree.

hiredman18:02:38

the next thing to do will be to look at your dependencies to make sure none of them are aot compiled with an older version of jdbc

mynomoto18:02:48

. org.clojure/java.jdbc 0.7.6 which should be good.

mynomoto18:02:52

Hum, should I look inside jars for that?

hiredman18:02:22

that stacktrace is also very odd to happen at runtime after aot compiling

hiredman18:02:03

(since it is coming from the compiler, which shouldn't happen if everything is aot compiled)

hiredman18:02:35

when you aot what you should get out is to some degree a function of what your build tool is, and how it manages its aot feature

mynomoto18:02:03

Ok, thanks for the direction. Will report back what I find. I found some .clj files on the uberjar, not sure if those are expected. I'm using depstar to create the uberjar.

seancorfield18:02:05

Especially since that function -- db-do-prepared-return-keys -- has been in c.j.j for a long time and hasn't been touched since that 0.7.6 release.

hiredman18:02:14

the way the clojure compiler handles it is all the code loaded while aot compiling generates classes

hiredman18:02:33

(well generates classes that are saved to disk"

hiredman18:02:07

so for example, if you are preloading any code before triggering aot compilation, it won't be aot compiled unless you reload it, which can be a problem

seancorfield18:02:25

@mynomoto Yes, if there are paths in the code that do not statically reference certain namespaces, those will not be AOT compiled for just :main-class with depstar. You could try :compile-ns :all.

seancorfield18:02:21

What version of HugSQL are you using BTW?

mynomoto18:02:20

com.layerware/hugsql 0.4.9 I checked the changelogs over there but I didn't find anything suspicious.

seancorfield18:02:27

That should be recent enough to be fine. I would check your dependencies with clojure -Stree and see if older versions are lurking elsewhere in your transitive deps.

mynomoto18:02:52

I just did that as suggested by @hiredman but there is only one reference both to clojure.java.jdbc and hugsql.

curtis.summers18:02:50

You might try hugsql 0.5.1, since there was a fix related to requiring and setting the adapter that might help with AOT issues.

mynomoto18:02:55

Ok, I will try that, thank you!

seancorfield18:02:31

Ah, yes. Somehow I'd missed the changes since 0.4.7 via the link I'd turned up. Here's the issue you're talking about @curtis.summers https://github.com/layerware/hugsql/issues/105 ?

mynomoto18:02:06

Oh, thank you! I missed that when searching on github.

seancorfield18:02:35

Looks like #46 introduced a regression that got fixed in 0.5.1 in #105

mynomoto18:02:10

I think this commit that was released on 0.5.0 was the one that fixed the issue but caused the bug that was fixed in 0.5.1 https://github.com/layerware/hugsql/commit/8a908f7a5de37d232183a3bebc2f9e4ab26812a3

mynomoto18:02:30

Thank you @hiredman, @seancorfield and @curtis.summers. Looks that upgrading to the latest version of hugsql should fix it.

👍 3