tortoise / tortoise/tortoise-orm

Awaiting `Model.bulk_create` on a list of objects returns None and also does not fill the `id` field of the list items!

Open
#1,992 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
5.6k
Forks
516
Avg merge
2d 21h
Merged PRs (30d)
9

Description

When you await Model.bulk_create on a list of objects it does not add the id fields for the objects.
And this is so lame that I account it as a bug not a feature request!

Sample code:

        accounts = []
        fake = Faker()

        kwargs_dict = dict(
            proxy=fake.random_int(min=1000, max=9999),
            color=fake.random_int(min=0, max=16777215),  # RGB range
            screen_resolution=fake.random_int(min=720, max=2160),
            profile=fake.random_int(min=1, max=1000),
            category=category,
            secret_key=fake.uuid4(),
            username=fake.user_name(),
            password=fake.password(),
            name=fake.name(),
            bio=fake.sentence(nb_words=10),
            email=fake.email(),
            profile_pic_url=fake.image_url(),
            instagram_state=fake.random_element(elements=["active", "inactive", "banned"]),
            app_state=fake.random_element(elements=["idle", "busy"]),
            avatar_changed=fake.random_int(min=0, max=1),
            username_changed=fake.random_int(min=0, max=1),
            initial_posts_deleted=fake.random_int(min=0, max=1),
            has_enough_posts=fake.random_int(min=0, max=1),
            is_used=fake.random_int(min=0, max=1),
            is_active=fake.random_int(min=0, max=1),
            is_public=fake.random_int(min=0, max=1),
            web_session=fake.uuid4(),
            mobile_session=fake.uuid4(),
            log=fake.text(max_nb_chars=200),
            updated_at=datetime.now(),
            next_login=datetime.now(),
        )
        accounts.append(Account(**kwargs_dict))

        t = Account.bulk_create(accounts, 10, True)   # t is None
        # accounts[0].id is also None

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the Model.bulk_create entry point shown in the sample and trace how Account.bulk_create handles the list of objects and its awaitable result. Check the existing bulk-insert behavior across the ORM's supported database paths. Done means the awaited operation has a defined result and the objects in the supplied list have their generated id fields populated, with tests covering the reported example.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.