Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spec for with-transaction is too strict #257

Closed
seancorfield opened this issue Sep 15, 2023 · 0 comments
Closed

Spec for with-transaction is too strict #257

seancorfield opened this issue Sep 15, 2023 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@seancorfield
Copy link
Owner

Describe the bug
Macros are spec-checked if an fdef spec exists, even without calling instrument. The spec for with-transaction requires a literal hash map for options so you cannot pass a variable.

To Reproduce

(~/oss/next-jdbc)-(!2007)-> clj -A:test
Clojure 1.11.1
user=> (require '[next.jdbc :as jdbc])
...
nil
user=> (require 'next.jdbc.specs)
nil
user=> (def db-spec {:dbtype "h2:mem" :dbname "with_t"})
#'user/db-spec
;; this is acceptable:
user=> (jdbc/with-transaction [s db-spec {:rollback-only true}] (jdbc/execute! s ["select * from mytable"]))
Execution error (JdbcSQLSyntaxErrorException) at org.h2.message.DbException/getJdbcSQLException (DbException.java:502).
Table "MYTABLE" not found (this database is empty); SQL statement:
select * from mytable [42104-214]
;; this should be acceptable too:
user=> (let [opts {:rollback-only true}] (jdbc/with-transaction [s db-spec opts] (jdbc/execute! s ["select * from mytable"])))
Syntax error macroexpanding next.jdbc/with-transaction at (REPL:1:35).
opts - failed: map? at: [:binding :opts] spec: :next.jdbc.specs/opts-map
user=>

Expected behavior
with-transaction should allow arbitrary forms for the options map. The underlying transact function should trap non-hash-map options, if instrumentation is enabled.

@seancorfield seancorfield added the bug Something isn't working label Sep 15, 2023
@seancorfield seancorfield self-assigned this Sep 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant