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

Parameter with false value not found #23

Closed
rcanepa opened this issue Feb 24, 2016 · 5 comments
Closed

Parameter with false value not found #23

rcanepa opened this issue Feb 24, 2016 · 5 comments
Labels

Comments

@rcanepa
Copy link

rcanepa commented Feb 24, 2016

For some reason, Clojure Expressions doesn't work when I pass a false keyword to the params map. To explain it better, I am executing the next function:

(s/defn fetch-invoices-filterable :- [schemas/Invoice]
  [db :- ConnectionMap
   parameters :- schemas/SearchParameters]
  (println parameters)
  (execute! db :select-invoices-filterable parameters))

And that function calls this SQL query:

-- :name select-invoices-filterable :? :*
-- :doc Retrieve invoices according to a group of filters.
SELECT
  i.id,
  i.type,
  i.legal_date,
  i.invoice_year,
  i.invoice_month,
  i.code,
  i.comments,
  i.start_date,
  i.end_date,
  i.is_paid,
  i.created_at,
  i.person_id,
  p.first_name AS person_first_name,
  p.legal_uid AS person_legal_uid,
  p.org_representative AS person_org_representative
FROM
  invoices i,
  people p
WHERE
  i.person_id = p.id
--~ (when (:person-identifier params) "AND upper(p.first_name) LIKE :person-identifier")
--~ (when-not (nil? (:org-representative params)) "AND p.org_representative = :org-representative")
--~ (when (:type params) "AND upper(i.type::varchar) LIKE :type")
--~ (when (:invoice-year params) "AND i.invoice_year = :invoice-year")
--~ (when (:invoice-month params) "AND i.invoice_month = :invoice-month")
--~ (when (:code params) "AND upper(i.code) LIKE :code")
--~ (when (:comments params) "AND upper(i.comments) LIKE :comments")
GROUP BY
  i.id,
  p.id
ORDER BY
  :i*:order-by-fields
OFFSET :offset
LIMIT :page-size;

And I am getting this error:

user=> {:org-representative false, :page 1, :page-size 20, :offset 0, :order-by-fields (i.created_at ASC)}
ERROR Parameter Mismatch: :org-representative parameter data not found.
clojure.lang.ExceptionInfo: Parameter Mismatch: :org-representative parameter data not found. {}
    at clojure.core$ex_info.invokeStatic(core.clj:4617)
    at clojure.core$ex_info.invoke(core.clj:4617)
    at hugsql.core$validate_parameters_BANG_.invokeStatic(core.clj:61)
    at hugsql.core$validate_parameters_BANG_.invoke(core.clj:55)
    at hugsql.core$prepare_sql.invokeStatic(core.clj:172)
    at hugsql.core$prepare_sql.invoke(core.clj:160)
    at hugsql.core$db_fn_STAR_$y__10617.doInvoke(core.clj:437)
    at clojure.lang.RestFn.invoke(RestFn.java:445)

In the first line you can see that I am passing the missing keyword org-representative. Also, If I execute the same function with :org-representative true everything works fine.

Any idea on what could be happening?

@rcanepa
Copy link
Author

rcanepa commented Feb 24, 2016

I forgot to say that I am using version 0.4.1 and Clojure 1.8.0.

@csummers
Copy link
Member

That's definitely a bug and one that I introduced with the deep-get parameter feature in 0.4.x. (commit e7d45f1).

I've fixed this in master and will be rolling a 0.4.2 release a bit later today.

Thanks for the report!

@rcanepa
Copy link
Author

rcanepa commented Feb 24, 2016

Excellent! I will be waiting for that.

@csummers
Copy link
Member

I just released 0.4.2. Please confirm this fixes the issue. Thanks!

@rcanepa
Copy link
Author

rcanepa commented Feb 24, 2016

Curtis, everything works fine now. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants