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

bulk_create() expects same column order for all data #772

Closed
circulon opened this issue Jul 22, 2022 · 0 comments · Fixed by #773
Closed

bulk_create() expects same column order for all data #772

circulon opened this issue Jul 22, 2022 · 0 comments · Fixed by #773
Labels
bug An existing feature is not working as intended

Comments

@circulon
Copy link
Contributor

circulon commented Jul 22, 2022

Describe the bug
Using a list of dicts for .bulk_create() where the keys for the individual dicts are not in exactly the same order will result in data inconsistency errors.
This may also trigger an exception for Type insertion, eg trying to insert am int into a uuid column.

To Reproduce
The following will insert the wrong values into the particular columns regardless of the key name. This is a result of the key order being taken from the first dict and then that same order being applied against all other dicts.

user = User.builder.new().bulk_create([{
    "name": "Joe4",
    "email": "test@domain.com",
    "password": "Joe",
}, {
    "password": "Joe",
    "name": "Joe5",
    "email": "another@domain.com",
}, {
    "email": "Joe6",
    "name": None,
    "password": "JoePass",
}])

This will result in 3 rows being created with the following data

name email password
Joe4 test@domain.com Joe
Joe Joe5 another@domain.com
Joe6 JoePass

I am putting together a PR to address this by simply sorting the keys in each dict
before passing them to the grammar compiler

Expected behavior
The values associated with each key in eack dict should be inerted in the correct column regardless of the order of the keys in each dict.

Desktop (please complete the following information):

  • OS: OSX
  • Version 12.4

What database are you using?

  • Type: Postgres
  • Version 10.5
  • Masonite ORM 2.18.1
@circulon circulon added the bug An existing feature is not working as intended label Jul 22, 2022
@circulon circulon mentioned this issue Jul 22, 2022
@circulon circulon changed the title bulk_create() expects key order of dicts in list to be the same bulk_create() expects same column order for all data Jul 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An existing feature is not working as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant