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

unique conflicts-> then decrementing cause out of bounds error #4

Open
stanlay01 opened this issue Apr 18, 2022 · 1 comment
Open

Comments

@stanlay01
Copy link

stanlay01 commented Apr 18, 2022

Hello,

First. I do not usually code in Python, so I had problems running it in version 3 of Python.

Second, there is a bug causing PK out of bounds.
If you have two databases: first_database, second_database
By incrementing first_database, you get primary keys like 1000001 and second_database primary keys like 2000001.

Then there is a step : " 7/9 Mapping pk in case of uniques conflict", which finds conflicts. In case of conflict second_database primary key change to 1000001.

In step 9: Decrementing pks: it tries to decrement - 2000000 primary keys in second database. But in those, where was conflict it goes out of bounds because it has changed.

my solution was to change function rollback_pks

                   where = ""
                   if len(table_map['pk_changed_to_resolve_unique_conficts']):
                       where = "WHERE %(pk_col)s NOT IN (%(ids)s)" % {
                           'pk_col': list(table_map['primary'].keys())[0],
                           'ids': ",".join(table_map['pk_changed_to_resolve_unique_conficts'])
                       }
                   
                   
                   self._logger.qs = "UPDATE `%(table)s` SET `%(pk)s` = `%(pk)s` - %(step)d %(where)s" % {"table": table_name,
                                                                                                "pk": col_name,
                                                                                                'step': self._increment_value,
                                                                                                'where': where}
                   where = ""
                   if len(table_map['pk_changed_to_resolve_unique_conficts']):
                       where = "WHERE %(pk_col)s IN (%(ids)s)" % {
                           'pk_col': list(table_map['primary'].keys())[0],
                           'ids': ",".join(table_map['pk_changed_to_resolve_unique_conficts'])
                       }
                   
                   
                   self._logger.qs = "UPDATE `%(table)s` SET `%(pk)s` = `%(pk)s` - %(step)d %(where)s" % {"table": table_name,
                                                                                                "pk": col_name,
                                                                                                'step': self._increment_step,
                                                                                                'where': where}
@adamziel
Copy link
Owner

adamziel commented Apr 20, 2022

Thank you so much for sharing that @stanlay01! Would you like to contribute to the codebase? If you turned this change into a Pull Request, I'd be more than happy to review and merge it.

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

No branches or pull requests

2 participants