sql

All things SQL and JDBC...
2021-02-25T12:14:19.061300Z

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)

2021-02-25T12:17:12.063300Z

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.

2021-02-25T12:18:22.064500Z

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.

2021-02-25T17:03:08.065100Z

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

2021-02-25T17:04:41.066600Z

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

2021-02-25T17:05:00.067Z

did you get that error compiling or when running?

2021-02-25T18:00:59.069300Z

@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.

2021-02-25T18:02:38.070400Z

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

2021-02-25T18:02:48.070600Z

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

2021-02-25T18:03:52.071500Z

Hum, should I look inside jars for that?

2021-02-25T18:03:58.071800Z

yes

2021-02-25T18:04:22.072300Z

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

2021-02-25T18:06:03.073100Z

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

2021-02-25T18:07:35.074900Z

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

2021-02-25T18:08:03.076100Z

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.

seancorfield 2021-02-25T18:08:05.076200Z

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.

2021-02-25T18:08:14.076400Z

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

2021-02-25T18:08:33.077Z

(well generates classes that are saved to disk"

2021-02-25T18:09:07.078200Z

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

seancorfield 2021-02-25T18:09:25.078400Z

@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.

seancorfield 2021-02-25T18:11:21.078700Z

What version of HugSQL are you using BTW?

2021-02-25T18:12:20.079500Z

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

seancorfield 2021-02-25T18:15:27.081100Z

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.

curtis.summers 2021-02-25T18:15:50.081700Z

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.

2021-02-25T18:16:52.082Z

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

2021-02-25T18:17:55.082200Z

Ok, I will try that, thank you!

2021-02-25T18:21:06.082800Z

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

2021-02-25T18:23:30.083900Z

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

👍 1
seancorfield 2021-02-25T18:41:31.085Z

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 ?

seancorfield 2021-02-25T18:42:35.085300Z

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

2021-02-25T18:56:10.085600Z

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