django-watson
django-watson copied to clipboard
Problem with watson during loaddata command call
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.
I suggest to check if raw=False
when catching the post_save signal in order to ignore actions made in loaddata call.
Sounds sensible, although it would require running a manual buildwatson command after using loaddata.
I'd take a pull request for this.
On 11 September 2018 at 20:45, Gabriel de Biasi [email protected] wrote:
I suggest to check if raw=False when catching the post_save signal in order to ignore actions made in loaddata call.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/etianen/django-watson/issues/250#issuecomment-420400028, or mute the thread https://github.com/notifications/unsubscribe-auth/AAJFCAbMrcbXT8W9HtYgBU2azH3HRu9Dks5uaBL1gaJpZM4WkF8Z .
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.
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
.