Page MenuHomePhabricator

Example data generation command breaking
Open, Needs TriagePublicBUG REPORT

Description

Steps to replicate the issue (include links if applicable):

On Running the example data generation command mentioned in the Local-setup guide

docker-compose exec twlight /app/bin/virtualenv_example_data.sh

What happens?:

It breaks with the following error message

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/venv/lib/python3.7/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/venv/lib/python3.7/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/venv/lib/python3.7/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/venv/lib/python3.7/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/app/TWLight/resources/management/commands/resources_example_data.py", line 55, in handle
    agreement_with_terms_of_use=self.chance(True, False, 10),
  File "/venv/lib/python3.7/site-packages/factory/base.py", line 40, in __call__
    return cls.create(**kwargs)
  File "/venv/lib/python3.7/site-packages/factory/base.py", line 528, in create
    return cls._generate(enums.CREATE_STRATEGY, kwargs)
  File "/venv/lib/python3.7/site-packages/factory/django.py", line 121, in _generate
    return super()._generate(strategy, params)
  File "/venv/lib/python3.7/site-packages/factory/base.py", line 465, in _generate
    return step.build()
  File "/venv/lib/python3.7/site-packages/factory/builder.py", line 277, in build
    kwargs=kwargs,
  File "/venv/lib/python3.7/site-packages/factory/base.py", line 317, in instantiate
    return self.factory._create(model, *args, **kwargs)
  File "/venv/lib/python3.7/site-packages/factory/django.py", line 174, in _create
    return manager.create(*args, **kwargs)
  File "/venv/lib/python3.7/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/venv/lib/python3.7/site-packages/django/db/models/query.py", line 453, in create
    obj.save(force_insert=True, using=self.db)
  File "/venv/lib/python3.7/site-packages/django/db/models/base.py", line 740, in save
    force_update=force_update, update_fields=update_fields)
  File "/venv/lib/python3.7/site-packages/django/db/models/base.py", line 789, in save_base
    update_fields=update_fields, raw=raw, using=using,
  File "/venv/lib/python3.7/site-packages/django/dispatch/dispatcher.py", line 182, in send
    for receiver in self._live_receivers(sender)
  File "/venv/lib/python3.7/site-packages/django/dispatch/dispatcher.py", line 182, in <listcomp>
    for receiver in self._live_receivers(sender)
  File "/app/TWLight/applications/signals.py", line 216, in invalidate_bundle_partner_applications
    twl_team = User.objects.get(username="TWL Team")
  File "/venv/lib/python3.7/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/venv/lib/python3.7/site-packages/django/db/models/query.py", line 437, in get
    self.model._meta.object_name
django.contrib.auth.models.DoesNotExist: User matching query does not exist.

What should have happened instead?:

It should have generated the example data.

Event Timeline

It looks to me like when we added the generic "TWL Team" account for invalidating applications that we no longer need, we neglected to add creation of that account to the example data scripts, so when some bundle applications get invalidated as part of generating the data, the account can't be found.

It looks to me like when we added the generic "TWL Team" account for invalidating applications that we no longer need, we neglected to add creation of that account to the example data scripts, so when some bundle applications get invalidated as part of generating the data, the account can't be found.

Okay, I think I got the issue somewhat, can I work on this ticket?

Hi and thank you for your interest! Please check thoroughly https://www.mediawiki.org/wiki/New_Developers (and all of its communication section!). The page covers how to get started, assigning tasks, task status, how to find a codebase, how to create patches, where to ask general development questions and where to get help with setup problems, and how to ask good questions. Thanks a lot! :)

It looks to me like when we added the generic "TWL Team" account for invalidating applications that we no longer need, we neglected to add creation of that account to the example data scripts, so when some bundle applications get invalidated as part of generating the data, the account can't be found.

Okay, I think I got the issue somewhat, can I work on this ticket?

Of course :)

One thing to look into - it's not clear to me why this test wouldn't have caught the problem: https://github.com/WikipediaLibrary/TWLight/blob/master/TWLight/tests.py#L485

Hi and thank you for your interest! Please check thoroughly https://www.mediawiki.org/wiki/New_Developers (and all of its communication section!). The page covers how to get started, assigning tasks, task status, how to find a codebase, how to create patches, where to ask general development questions and where to get help with setup problems, and how to ask good questions. Thanks a lot! :)

I couldn't reproduce this locally - I just set up my local environment fresh and ran the script, cleared my database, then ran it a second time, and didn't get the issue either time. There's some randomness involved in the scripts, so I wonder if this only happens under certain conditions.

Were you running the script on an empty database, or having already added some data?