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

Implement multi-column constraints. #73

Conversation

AndTheDaysGoBy
Copy link
Contributor

Created for #72.

This allows for the pass-through of table arguments to the underlying sqlalchemy table. In particular, the passing of UniqueConstraint.

This PR should not be considered complete, but requesting input. Two subjects of particular concern are:

  • the above implementation will require importing UniqueConstraint from sqlalchemy.schema when used. Is this fine? Theoretically this multi-column uniqueness shouldn't be as prevalent as single column uniqueness (which only requires passing unique=True). Thus, perhaps it makes sense to necessitate directly reference to sqlalchemy in these rare cases.
  • As can be seen in my test, I perform from sqlite3 import IntegrityError. This is what I used because the exception raised by aiosqlite is not encapsulated by from sqlalchemy.exc import IntegrityError. Thus, I question how to deal with the issue that aiosqlite's IntegrityError isn't being caught using a cross-DB solution.

More on the second point, I don't know if that means I should open up an issue with aiosqlite.

Copy link
Contributor Author

@AndTheDaysGoBy AndTheDaysGoBy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, looking at the stack-trace, it makes sense sqlalchemy.exc.IntegrityError isn't caught, I think, because sqlalchemy isn't used at all? The flow is orm/models.py to databases/core.py to (due to my use case) databases/backends/sqlite.py to aiosqlite/cursor.py to aiosqlite/core.py.

Edit:
OK, seems that there is an upstream issue for this: encode/databases#162.

await Channel.objects.create(name='PBS', number=2)
await Channel.objects.create(name='CSPAN', number=2)

from sqlite3 import IntegrityError
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was using sqlite. In theory sqlalchemy.exc.IntegrityError should catch this (I believe). However, the exception raised within aiosqlite could only be caught by sqlite3.IntegrityError.

@xloem xloem mentioned this pull request Aug 9, 2021
@aminalaee aminalaee closed this Nov 23, 2021
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.

2 participants