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

include primary_key for upsert to avoid ValueError #143

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jzcruiser
Copy link
Contributor

When syncing a single column table from dolt to mysql,
sqlalchemy will throw a ValueError complaining about an empty update_dict

CREATE TABLE authority (
name varchar(50) NOT NULL,
PRIMARY KEY (name)
) ENGINE=InnoDB DEFAULT
CHARSET=utf8;

https://github.com/zzzeek/sqlalchemy/blob/857adaaf867df54d4a023cf19f618fdf1d0f60c9/lib/sqlalchemy/dialects/mysql/dml.py#L150

When syncing a single column table from dolt to mysql,
sqlalchemy will throw a ValueError complaining about an empty update_dict

CREATE TABLE `authority` (
  `name` varchar(50) NOT NULL,
  PRIMARY KEY (`name`)
) ENGINE=InnoDB DEFAULT 
CHARSET=utf8;

https://github.com/zzzeek/sqlalchemy/blob/857adaaf867df54d4a023cf19f618fdf1d0f60c9/lib/sqlalchemy/dialects/mysql/dml.py#L150
@codecov-io
Copy link

Codecov Report

Merging #143 (d1183e8) into master (e7dfa97) will decrease coverage by 13.37%.
The diff coverage is 65.90%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master     #143       +/-   ##
===========================================
- Coverage   55.06%   41.69%   -13.38%     
===========================================
  Files          25       23        -2     
  Lines        1718      957      -761     
===========================================
- Hits          946      399      -547     
+ Misses        772      558      -214     
Impacted Files Coverage Δ
doltpy/sql/__init__.py 100.00% <ø> (ø)
doltpy/sql/sync/__init__.py 0.00% <0.00%> (ø)
doltpy/sql/sync/dolt.py 0.00% <0.00%> (ø)
doltpy/sql/sync/mysql.py 0.00% <0.00%> (ø)
doltpy/sql/sql.py 77.05% <66.66%> (+0.09%) ⬆️
doltpy/cli/__init__.py 100.00% <100.00%> (ø)
doltpy/cli/dolt.py 100.00% <100.00%> (+46.16%) ⬆️
doltpy/cli/read.py 100.00% <100.00%> (ø)
doltpy/cli/write.py 100.00% <100.00%> (ø)
doltpy/etl/loaders.py 86.89% <100.00%> (ø)
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 52b5622...d1183e8. Read the comment docs.

@oscarbatori oscarbatori requested a review from max-hoffman March 26, 2021 17:05
@jzcruiser jzcruiser marked this pull request as ready for review March 28, 2021 08:28
@jzcruiser
Copy link
Contributor Author

Hi @max-hoffman , I don't know how to increase the code coverage yet. Please kindly advise.

@max-hoffman
Copy link
Collaborator

The diff coverage would probably look OK if you merged master, a one line change wouldn't have that big of an effect.

@@ -27,6 +27,6 @@ def get_target_writer(engine: Engine, update_on_duplicate: bool = True) -> DoltA

def upsert_helper(table: Table, data: List[dict]):
insert_statement = insert(table).values(data)
update_dict = {el.name: el for el in insert_statement.inserted if not el.primary_key}
update_dict = {el.name: el for el in insert_statement.inserted}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe @oscarbatori would be able to comment on the original code -- is there any unexpected behavior when we drop this primary key filter? Should we instead have a short circuit return if update_dict is empty? I have not spent a lot of time with the SQL-sync code since joining, can look at this more tomorrow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your advice. I tried a short circuit return, but the code I wrote was not clean enough, and that lead to this one line change.

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