-
Notifications
You must be signed in to change notification settings - Fork 262
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
in-memory sqlite odd behavior #75
Comments
Well, in memory will only be persisted for the duration of the python session. You might also want to double check against what behaviour sqlite3 has. Does “creating the tables” for an in memory DB actually do anything? |
I’m going to close this off - if you thing there’s a active issue, and (ideally) can build a test case for it then we could reconsider. |
I meant within a python session.
I'm not sure if you are being sarcastic or actually asking a question. Fair enough. Leave it close. |
I’m not. I’d suggest start by comparing sqlite3’s behaviour vs ours. If you’ve double checked that it’s definitely different, and can give a minimal replicable example then i’ll happily reopen and put my time into it. I’d just like to have a clear confirmation that there’s an issue this side, before commiting time in. |
Here is an example of what I mean:
If you switch to a file db, then the table will be printed. In-memory will not have the table listed. On the other hand, plain sqlite3 works as expected:
|
Gotcha, thanks! |
Presumably something like create table not being effected until the connection is closed? It’s be worth trying to dig into exactly what set of operations are being performed against the underlying driver, and also worth checking if you can replicate in aiosqlite directly (or if their project has any issues similar to this) |
Indeed. I wil try to see what I can dig up tomorrow. |
This seems to play out as expected:
does output the table name. I tried the idea of disconnecting and coinnecting again with databases:
But with no luck. |
Okay - that's really strange. I guess the next level would be to get a debug log of exactly what sequence of calling into the |
Yeah, I cannot see that jumps out of the ordinary in the code. |
@Lawouach The
|
Agreed. However that's not the initial case I reported. It was an hypothesis. |
@tomchristie: I ran into this issue recently with a co-worker. Hopefully this debug output is helpful to you. Using in-memory SQLite with
|
I experience exactly the same issue. Although this repo is awesome 🚀 , I think that in-memory databases are essential for unit testing. Have you any progress on that (maybe some code or tips)? Otherwise I would have to go with file database 🐿️ |
No extra feedback here, no. 🤷♂️ |
Me neither. I went the route of file backend and that's okay for my tests I guess. |
+1 for experiencing the same issue. |
The problem is that
So once the statement finishes, the connection is closed and the in-memory DB is deleted:
To fix this, you need to share a single
Once #196 is done it should be possible to share in-memory databases using |
Oh, and for testing purposes, the workaround I'm using is a file database in a temp directory:
|
Hello there! I have noticed you have used codes like this:
But you have already defined your table with:
So I'd like to ask you a question, can the I don't think it's a smart thing to create the table again with low level I hope to see a clear answer to it. |
No Bother, No need to answer me, I just figured out how to work with https://yingshaoxo.blogspot.com/2020/06/how-to-work-with-databases-and.html |
This includes the initial migration to create the table and minimal setup of the tests to have the database around. Ideally the test database would be in memory, however there seem to be issues within the databases library around that (encode/databases#75).
I would suggest that this issue be reopened. The link in the reply from @yingshaoxo uses an file databases, and as such doesn't actually resolve this. With sqlite I would run |
Agreed. |
@brendanlong could you please show hot to use it in context in a test with imports? |
I had the same issue. By looking at the code, it seems like a possible fix for running unittests are to connect to the database with |
Hi,
Thanks for the awesome package (happy to use it with starlette). For rapid dev purpose, I'm relying on the SQLite backend and I see an odd behavior.
When I create tables with an in-memory db, those tables can never be found in sqlite_master afterwards. But when I rely on a file database, then that works fine.
Is there any gotcha for in-memory sqllite I should be aware of?
Cheers,
The text was updated successfully, but these errors were encountered: