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

Prevent or improve error message when mixing drivers #670

Open
cvogt opened this issue Feb 11, 2014 · 20 comments
Open

Prevent or improve error message when mixing drivers #670

cvogt opened this issue Feb 11, 2014 · 20 comments

Comments

@cvogt
Copy link
Member

cvogt commented Feb 11, 2014

It seems to happen every once in a while that people accidentally use different Slick drivers for defining their table classes and for running queries, especially when using different databases in development, testing and production.

Here is one of several instances from the mailing list: https://groups.google.com/forum/#!searchin/scalaquery/TypeInfo/scalaquery/8zghyUwEONo/-GMkrE2Xm8gJ

We should either prevent this problem statically or at least throw a better error message.

@szeiger szeiger added this to the 2.1 milestone Feb 12, 2014
@cvogt
Copy link
Member Author

cvogt commented Feb 13, 2014

related to #48

@david-wilson
Copy link

What's the best option for dealing with this? I am writing my app against Postgres, but trying to use H2 for the tests, using the PostgresQL mode. I receive the error referenced in the mailing list thread.

@cvogt
Copy link
Member Author

cvogt commented Mar 25, 2014

Make sure you import the same driver when defining your table and where you run queries (i.e. where you use Database and withSession. You can use the cake pattern for that. If you use the code generator you can extend the generated Tables trait and set the profile member to the required driver. Does that help?

@david-wilson
Copy link

I'm using the play-slick plugin, so I am not explicitly defining a driver outside my configuration. I am not sure how to extend the Tables trait in this case. I can provide code, if needed.

@szeiger
Copy link
Member

szeiger commented Mar 25, 2014

BTW, I did some work on this recently in https://github.com/slick/slick/tree/tmp/scalatypes-in-drivers. It needs to be rebased on top of the fast path converters work and I'm not sure if it's the right direction in general, but it would solve this issue.

@cvogt
Copy link
Member Author

cvogt commented Mar 27, 2014

@david-wilson if you provide code that reproduces the issue for you, I can take a look

@cvogt
Copy link
Member Author

cvogt commented Apr 2, 2014

Another instance: #744

@szeiger
Copy link
Member

szeiger commented Apr 3, 2014

No, #744 is about using the wrong driver for a database. There's no (cheap, non-hacky) way to prevent this.

@cvogt
Copy link
Member Author

cvogt commented Apr 3, 2014

He creates a column, which comes from a Table, which comes from a driver. Invoker or else could check that you run a query against the same driver you used to define it and throw a useful exception if not. Doesn't seem hacky to me. Am I missing something?

@szeiger
Copy link
Member

szeiger commented Apr 3, 2014

But that is the case there, everything is run with H2Driver, just the database connection and JDBC driver is for Postgres.

@cvogt
Copy link
Member Author

cvogt commented Apr 3, 2014

Ok, not the exact problem, but related. Mixing wrong combinations of Slick and JdbcDrivers. We could emit a warning (that can be disabled) if somebody doesn't use the jdbc driver we expect, or even better pick the right jdbc driver by default and let people override it. In almost all cases people use exactly the same driver (or 1 out of 2 in case of sqlserver). Better than failing with weird behavior like #744.

@szeiger
Copy link
Member

szeiger commented Apr 3, 2014

No, we couldn't, because in real world applications we don't even see the driver. The Connection comes from a pool.

@cvogt
Copy link
Member Author

cvogt commented Apr 3, 2014

good point... mh... on the other hand, people stumble over these problems when trying slick, which is not a "real world application" but an important use case for Slick adoption. So I still think this check makes sense.

@cvogt
Copy link
Member Author

cvogt commented Apr 10, 2014

Another instance where somebody had problems with configuring the Slick driver together with the corresponding jdbc driver. https://groups.google.com/d/msgid/scalaquery/b07a1215-768a-4638-8050-3561dca4c4ba%40googlegroups.com

We should really pick a default jdbc driver for a slick driver in my eyes!

@cvogt cvogt self-assigned this Apr 10, 2014
@nafg
Copy link
Member

nafg commented Apr 13, 2014

Maybe the slick drivers could provide shorthand Database factories, that
preselect the driver class, and maybe let you specify the connection string
without the jdbc prefix boilerplate. The methods could have distinct names
and only exist in the concrete drivers. They could even be different for
different drivers, for instance some could take the values that the
connection string needs and build the connection string for you. And
database types that have multiple jdbc drivers could have separate methods
for each.
On Apr 10, 2014 7:50 AM, "Jan Christopher Vogt" notifications@github.com
wrote:

Another instance where somebody had problems with configuring the Slick
driver together with the corresponding jdbc driver.
https://groups.google.com/d/msgid/scalaquery/b07a1215-768a-4638-8050-3561dca4c4ba%40googlegroups.com

We should really pick a default jdbc driver for a slick driver in my eyes!

Reply to this email directly or view it on GitHubhttps://github.com//issues/670#issuecomment-40069137
.

@szeiger
Copy link
Member

szeiger commented Apr 14, 2014

I wouldn't want to provide such methods unless we add connection pooling out of the box. We shouldn't encourage users not to use a connection pool.

@cvogt
Copy link
Member Author

cvogt commented May 26, 2014

Another instance where subtle mixing up drivers lead to a lot of confusion: #794

@cvogt
Copy link
Member Author

cvogt commented Jun 29, 2014

@cvogt
Copy link
Member Author

cvogt commented Jun 29, 2014

Related to #419

@szeiger
Copy link
Member

szeiger commented Jun 30, 2014

As pointed out in #801, this looks like a bug in play-slick. You're supposed to use the injected singleton driver there, and if you do that consistently, none of these problems should occur.

@szeiger szeiger removed this from the 3.0.0 milestone Jan 29, 2015
@szeiger szeiger modified the milestones: 3.1.0, 3.2.0 Sep 10, 2015
@szeiger szeiger modified the milestones: 3.2.0, 3.2.1 Jan 24, 2017
@hvesalai hvesalai modified the milestones: 3.2.1, Future, Feature ideas, Documentation ideas Feb 28, 2018
@cvogt cvogt removed their assignment Mar 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants