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

First call to format with :dialect may fail #441

Closed
valerauko opened this issue Nov 8, 2022 · 4 comments
Closed

First call to format with :dialect may fail #441

valerauko opened this issue Nov 8, 2022 · 4 comments
Assignees
Labels
bug It's broken, I'll fix it!

Comments

@valerauko
Copy link

user=> (honey.sql/format
  {:replace-into :accounts
   :values [{:public-key 1 :private-key 2}]
   :returning [:*]})
ExceptionInfo These SQL clauses are unknown or have nil values: :replace-into {:replace-into :accounts}
user=> (honey.sql/format
  {:replace-into :accounts
   :values [{:public-key 1 :private-key 2}]
   :returning [:*]}
  {:dialect :mysql
   :quoted-kebab true})
ExceptionInfo These SQL clauses are unknown or have nil values: :replace-into {:replace-into :accounts}

Then from the next call on it'd succeed.

user=> (honey.sql/format
  {:replace-into :accounts
   :values [{:public-key 1 :private-key 2}]
   :returning [:*]}
  {:dialect :mysql
   :quoted-kebab true})
["REPLACE INTO `accounts` (`public-key`, `private-key`) VALUES (?, ?) RETURNING *" 1 2]
user=> (honey.sql/format
  {:replace-into :accounts
   :values [{:public-key 1 :private-key 2}]
   :returning [:*]})
["REPLACE INTO accounts (public_key, private_key) VALUES (?, ?) RETURNING *" 1 2]

honeysql/src/honey/sql.cljc

Lines 107 to 110 in 23be700

:clause-order-fn
#(do
(register-clause! :replace-into :insert-into :insert-into)
(add-clause-before % :set :where))}

Maybe the :clause-order-fn is called at the wrong time and/or the clause dictionary is deref'd before it so it's not updated for the first call?

Workaround

  • using set-dialect! before any format calls
  • not using :mysql
@seancorfield seancorfield self-assigned this Nov 8, 2022
@seancorfield seancorfield added the bug It's broken, I'll fix it! label Nov 8, 2022
@seancorfield
Copy link
Owner

Your deduction of the bug is spot on: the argument to :clause-order-fn is the base clause order so it has already been derefed and passed in before register-clause! does its thing.

@valerauko
Copy link
Author

Thanks for the blazing fast fix! <3

@seancorfield
Copy link
Owner

Let me know if it actually solves the problem for you without introducing any new problems! There should be a new SNAPSHOT you can depend on from Clojars or you can test against git deps.

@valerauko
Copy link
Author

valerauko commented Nov 8, 2022

I can confirm the first call to format with :dialect now works! (And I don't see anything breaking.) Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug It's broken, I'll fix it!
Projects
None yet
Development

No branches or pull requests

2 participants