mcfunley / pugsql

A HugSQL-inspired database library for Python
https://pugsql.org
Apache License 2.0
681 stars 22 forks source link

Improve errors when calling methods without keyword params #39

Closed mcfunley closed 4 years ago

mcfunley commented 4 years ago

See discussion in issue: https://github.com/mcfunley/pugsql/issues/38

When calling a query method as:

queries.foo(1, 2)

Rather than:

queries.foo(a=1, b=2)

You get an unhelpful error. Ideally the exception text would tell you to use kwargs.

Yeganloo commented 4 years ago

Is it good idea to catch the exception and raise a new one with new message? I am not good with try cache as they effect on performance, specially not on the data-layer! Can pugsql compiler detect if the queries are using keys or positional arguments? Of-course it make compiler more complex but this way it is possible to use python typing system and prevent this kind of problems, beside no overhead in runtime will be added!

mcfunley commented 4 years ago

Fixed here https://github.com/mcfunley/pugsql/commit/9c36a104584c76848d2a4f08f2dad08f1905c295