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

WIP: Initial code for aiosqlite and base async backend #15357

Closed

Conversation

Andrew-Chen-Wang
Copy link
Contributor

@Andrew-Chen-Wang Andrew-Chen-Wang commented Jan 25, 2022

Adding async backend Base and aiosqlite -- someone else can pick it up if I become inactive.

  • Adds aatomic and an async atomic
  • Adds alru_cache
  • Internal django test cases can skip if it's an async or sync backend.

aatomic probably shouldn't have been implemented in this PR, but I also couldn't think of another time it could be implemented without a Base async backend.

There is no associated ticket as of yet. This was made a month ago, but because I could never pick this up due to classes, I made a PR for others to take advantage of. I should have time after February 20th to get back to this.

To write transaction test cases, it requires the async ORM.

* Include async alru_cache and aatomic

Signed-off-by: Andrew-Chen-Wang <acwangpython@gmail.com>
@Andrew-Chen-Wang Andrew-Chen-Wang marked this pull request as draft January 25, 2022 18:11
* This should help with identifying whether an engine can perform a certain task
* Added async transaction tests cases and backend + introspection test cases
* Fixed AsyncContextDecorator only being a Python 3.10 feature

The initial thought for using ASYNC_DATABASES was so that Django internally for its test suite could skip a test module if it required a sync driver and not an async driver or vice versa.

The issue is DEP 9 states that migrations should be synchronous only (probably to reduce number of lines of code). This means an implementation performed here will be used for Django users as well. This commit does not include a way to do that, but instead of ASYNC_DATABASES, we use SYNC_DATABASES in the Django settings. This is so that Django

Signed-off-by: Andrew-Chen-Wang <acwangpython@gmail.com>
@Andrew-Chen-Wang

This comment was marked as outdated.

* Fix async with cursor creation
* Use connections["async"] directly for POC sake
* Properly close connections in test cases

Test suite does hang for some reason

Signed-off-by: Andrew-Chen-Wang <acwangpython@gmail.com>
* Fix async with cursor creation in Django core files themselves

Signed-off-by: Andrew-Chen-Wang <acwangpython@gmail.com>
* Don't use mirrors
* Fixed other missing attribute bugs

Signed-off-by: Andrew-Chen-Wang <acwangpython@gmail.com>
* Fix TransactionTestCase to properly handle atomic blocks (can't use async_to_sync)

Signed-off-by: Andrew-Chen-Wang <acwangpython@gmail.com>
@Andrew-Chen-Wang
Copy link
Contributor Author

Can't seem to figure out why the socket is not being closed (assuming this is the async side):

Exception ignored in: <socket.socket fd=3, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('127.0.0.1', 58768), raddr=('127.0.0.1', 58766)>
ResourceWarning: unclosed <socket.socket fd=3, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('127.0.0.1', 58768), raddr=('127.0.0.1', 58766)>

Andrew-Chen-Wang and others added 5 commits March 13, 2022 12:31
Signed-off-by: Andrew-Chen-Wang <acwangpython@gmail.com>
Signed-off-by: Andrew-Chen-Wang <acwangpython@gmail.com>
Signed-off-by: Andrew-Chen-Wang <acwangpython@gmail.com>
@Shankar-Balaji-U
Copy link

from channels.db import database_sync_to_async

@database_sync_to_async
def get_user(mobile_no):
	return MyModel.objects.get(mobile_no=mobile_no)


user = get_user("9999999999")

it's works fine!!!

@felixxm
Copy link
Member

felixxm commented Mar 15, 2024

Closing due to inactivity.

@felixxm felixxm closed this Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants