-
Notifications
You must be signed in to change notification settings - Fork 14.1k
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
Fix #529 2 - "This Session's transaction has been rolled back" #531
Conversation
|
Hi, I noticed that the migrations fails on sqlite. The problem is linked to the fact that SQL Lite does not support alter tables and I have to use a batch alter instead:
The problem with this approach is that the sqlite schema doesn't have a name on the foreign key so there's no way I could drop it. |
@LAlbertalli since sqlite is the default db please add the batch context manager to keep caravel working out of the box. |
@xrmx Please, read my full comment. This kind of migration is not supported in sqlite because the constraint as no name. Otherwise, I would have submitted it immediately. That's why I'm asking for the best approach. There's a point to be made, though. Foreign keys are not on by default on sqlite, that's probably why none noticed the bug before. Could we modify the init migrations to have the correct foreign key and we conditionally skip the migration for sqlite? I don't like the idea because it will introduce an unpredictable behavior. On the other side, it is the only upgrade path I could foresee that doesn't require an overly complex setup. I'm open to suggestion. |
@LAlbertalli does this help? http://alembic.readthedocs.io/en/latest/batch.html#dropping-unnamed-or-named-foreign-key-constraints UPDATE: it looks it breaks mysql, see #466 which looks like the same issue as #529 |
@xrmx Yes, that was the same issue I found trying with the suggestion in the doc you linked. I need to do further research, this is why I was asking further suggestion from people more experienced than me in using SQLAlchemy/Alembic. |
@xrmx Seems like it only works when you have created the foreign keys with naming_convention specified. But it's too late now, for those who has been using mysql, the foreign keys have been named according to the default name convention of MySQL. The only solution I have figured out so far is to try on every kind of databases and try to drop the key by trying through each of the default foreign key names. |
@xrmx @x4base I see two options moving forward. Modifying the init migration to fix the error. I'm not happy with that but it should solve the issue for new install. People who are already using it, or they don't check foreign keys, or they have already fixed it. The second option, that I actually like more, is to surround the migration with an exception handling code to skip sqlite and find the correct name for PGSQL. To be honest, I will go for both actions (change init and use error handling) to cover all the possible issues. Let me know what do you prefer. It will take me probably few days to provide the patch. Bye |
I agree with droping the key by the pgsql. But i am concerned about whether we should cover more Sql dialects (e.g. mssql) that sqlalchemy supports or should we just assume that no one is using other dialects? |
@x4base I was thinking of sqlite, MySQL, and pg because they are the databases listed in https://github.com/airbnb/caravel/blob/master/caravel/config.py#L35 as an example. But, yes, nothing forbid to use MS SQL or Oracle. If someone has ideas... |
removing duplicated `user_id` def
* Fixing the specific issue * Added an additional fix for a similar error in #529 Background: - When an object is modified by SQLAlchemy, it is invalidated so need to be fetched again from the DB - If there's an exception during a transaction, SQLAlchemy performs a rollback and mark the connection as dirty. Bug: - When handling exceptions, the exception handler tries to access the name of the cluster in the main object. Since the name has been invalidated due to a write, SQLAlchemy tries to fetch it on a 'dirty' connection and spits out an error. Solution: - Fetch the information for handling the exception before starting the process.
…reign keys based on the signature. It supports also sqlite using batch migrations
The last commit should work for every supported DB. I've tested it against sqlite and partially tested against MySQL and it worked both upgrade and downgrade. The "magic" is done by a function that uses the sqlalchemy reflection capability to detect the correct constraint name. |
"fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s", | ||
} | ||
|
||
def find_constraint_name(upgrade = True): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On top of this should we probabily generalize this function so can be reused in other migrations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree in general.
There's just a question of timing, I don't have much time to dedicate on this bug fix right now and I think this issue is pretty urgent (basically Druid doesn't work on any DB that support Foreign Keys).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, i can do it after this is in :)
👍 |
…che#531) Bumps [@storybook/addon-actions](https://github.com/storybookjs/storybook/tree/HEAD/addons/actions) from 5.3.18 to 5.3.19. - [Release notes](https://github.com/storybookjs/storybook/releases) - [Changelog](https://github.com/storybookjs/storybook/blob/next/CHANGELOG.md) - [Commits](https://github.com/storybookjs/storybook/commits/v5.3.19/addons/actions) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
…che#531) Bumps [@storybook/addon-actions](https://github.com/storybookjs/storybook/tree/HEAD/addons/actions) from 5.3.18 to 5.3.19. - [Release notes](https://github.com/storybookjs/storybook/releases) - [Changelog](https://github.com/storybookjs/storybook/blob/next/CHANGELOG.md) - [Commits](https://github.com/storybookjs/storybook/commits/v5.3.19/addons/actions) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
…che#531) Bumps [@storybook/addon-actions](https://github.com/storybookjs/storybook/tree/HEAD/addons/actions) from 5.3.18 to 5.3.19. - [Release notes](https://github.com/storybookjs/storybook/releases) - [Changelog](https://github.com/storybookjs/storybook/blob/next/CHANGELOG.md) - [Commits](https://github.com/storybookjs/storybook/commits/v5.3.19/addons/actions) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
…che#531) Bumps [@storybook/addon-actions](https://github.com/storybookjs/storybook/tree/HEAD/addons/actions) from 5.3.18 to 5.3.19. - [Release notes](https://github.com/storybookjs/storybook/releases) - [Changelog](https://github.com/storybookjs/storybook/blob/next/CHANGELOG.md) - [Commits](https://github.com/storybookjs/storybook/commits/v5.3.19/addons/actions) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
This pull request fixes the second issue found on #529
Bug:
Fix: