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

Problem with watson during loaddata command call #250

Open
gabrielbiasi opened this issue Sep 11, 2018 · 4 comments
Open

Problem with watson during loaddata command call #250

gabrielbiasi opened this issue Sep 11, 2018 · 4 comments

Comments

@gabrielbiasi
Copy link

gabrielbiasi commented Sep 11, 2018

One of my models has "db-related" url. When I call get_absolute_url will hit the database.

When I use loaddata to load a dump of my app, watson already tries to use the object and hit the get_absolute_url method, resulting in a "matching query does not exist" and stop all the process.

Is there a way to tell watson to not try anything during a loaddata call?

Resulting trace:

Loading fixtures...
Traceback (most recent call last):
File "manage.py", line 16, in
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.6/site-packages/django/core/management/init.py", line 381, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.6/site-packages/django/core/management/init.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.6/site-packages/django/core/management/commands/loaddata.py", line 72, in handle
self.loaddata(fixture_labels)
File "/usr/local/lib/python3.6/site-packages/django/core/management/commands/loaddata.py", line 113, in loaddata
self.load_label(fixture_label)
File "/usr/local/lib/python3.6/site-packages/django/core/management/commands/loaddata.py", line 177, in load_label
obj.save(using=self.using)
File "/usr/local/lib/python3.6/site-packages/django/core/serializers/base.py", line 219, in save
models.Model.save_base(self.object, using=using, raw=True, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/db/models/base.py", line 757, in save_base
update_fields=update_fields, raw=raw, using=using,
File "/usr/local/lib/python3.6/site-packages/django/dispatch/dispatcher.py", line 175, in send
for receiver in self._live_receivers(sender)
File "/usr/local/lib/python3.6/site-packages/django/dispatch/dispatcher.py", line 175, in
for receiver in self._live_receivers(sender)
File "/usr/local/lib/python3.6/site-packages/watson/search.py", line 515, in _post_save_receiver
self.update_obj_index(instance)
File "/usr/local/lib/python3.6/site-packages/watson/search.py", line 506, in update_obj_index
_bulk_save_search_entries(list(self._update_obj_index_iter(obj)))
File "/usr/local/lib/python3.6/site-packages/watson/search.py", line 485, in _update_obj_index_iter
"url": adapter.get_url(obj),
File "/usr/local/lib/python3.6/site-packages/watson/search.py", line 154, in get_url
return obj.get_absolute_url()
File "/web/pages/models.py", line 46, in get_absolute_url
default = self.slugs.get(default=True)
File "/usr/local/lib/python3.6/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 399, in get
self.model._meta.object_name
pages.models.DoesNotExist: Problem installing fixture '/web/core/fixtures/dump.json': Slug matching query does not exist.

@gabrielbiasi
Copy link
Author

I suggest to check if raw=False when catching the post_save signal in order to ignore actions made in loaddata call.

@etianen
Copy link
Owner

etianen commented Sep 12, 2018 via email

@gabrielbiasi
Copy link
Author

I will appreciate this.
Thank you for your time.

Sounds sensible, although it would require running a manual buildwatson command after using loaddata. I'd take a pull request for this.

@gabrielbiasi
Copy link
Author

gabrielbiasi commented Sep 13, 2018

I made a workaround for this, using an environment variable.
NOINDEX=1 python manage.py loaddata */fixtures/*.json

And in apps.py:

if 'NOINDEX' not in os.environ:
watson.register(self.get_model('MyModel'))

After that, I call buildwatson.

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