Project

Profile

Help

Issue #5226

closed

Migration 0004_add_fulltext_search_indexes fails when trying to udpate search verctor

Added by osapryki over 4 years ago. Updated over 3 years ago.

Status:
CLOSED - CURRENTRELEASE
Priority:
High
Assignee:
Sprint/Milestone:
-
Start date:
Due date:
Estimated time:
Severity:
3. High
Platform Release:
OS:
Triaged:
No
Groomed:
No
Sprint Candidate:
No
Tags:
Sprint:
Sprint 57
Quarter:

Description

Migration 0004_add_fulltext_search_indexes fails with the following exception when trying to execute against database table that actually contains data.

Traceback (most recent call last):
  File "/venv/bin/django-admin", line 11, in <module>
    sys.exit(execute_from_command_line())
  File "/venv/lib64/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/venv/lib64/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/venv/lib64/python3.6/site-packages/django/core/management/base.py", line 323, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/venv/lib64/python3.6/site-packages/django/core/management/base.py", line 364, in execute
    output = self.handle(*args, **options)
  File "/venv/lib64/python3.6/site-packages/django/core/management/base.py", line 83, in wrapped
    res = handle_func(*args, **kwargs)
  File "/venv/lib64/python3.6/site-packages/django/core/management/commands/migrate.py", line 234, in handle
    fake_initial=fake_initial,
  File "/venv/lib64/python3.6/site-packages/django/db/migrations/executor.py", line 117, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/venv/lib64/python3.6/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/venv/lib64/python3.6/site-packages/django/db/migrations/executor.py", line 245, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/venv/lib64/python3.6/site-packages/django/db/migrations/migration.py", line 124, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/venv/lib64/python3.6/site-packages/django/db/migrations/operations/special.py", line 105, in database_forwards
    self._run_sql(schema_editor, self.sql)
  File "/venv/lib64/python3.6/site-packages/django/db/migrations/operations/special.py", line 130, in _run_sql
    schema_editor.execute(statement, params=None)
  File "/venv/lib64/python3.6/site-packages/django/db/backends/base/schema.py", line 137, in execute
    cursor.execute(sql, params)
  File "/venv/lib64/python3.6/site-packages/django/db/backends/utils.py", line 99, in execute
    return super().execute(sql, params)
  File "/venv/lib64/python3.6/site-packages/django/db/backends/utils.py", line 67, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/venv/lib64/python3.6/site-packages/django/db/backends/utils.py", line 76, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/venv/lib64/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/venv/lib64/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/venv/lib64/python3.6/site-packages/django/db/backends/utils.py", line 82, in _execute
    return self.cursor.execute(sql)
django.db.utils.ProgrammingError: more than one row returned by a subquery used as an expression

The SQL query that causes this exception is this:

        UPDATE ansible_collectionversion AS c
        SET search_vector = (
            SELECT 
            setweight(to_tsvector(coalesce(namespace,'')), 'A')
            || setweight(to_tsvector(coalesce(name, '')), 'A')
            || (
              SELECT
                setweight(to_tsvector(
                  coalesce(string_agg("ansible_tag"."name", ' '), '')
                ), 'B')
              FROM
                "ansible_tag" INNER JOIN "ansible_collectionversion_tags" ON ("ansible_tag"."_id" = "ansible_collectionversion_tags"."tag_id")
            )
            || (
              SELECT
                setweight(to_tsvector(
                  coalesce(string_agg(cvc ->> 'name', ' '), '')
                ), 'C')
              FROM jsonb_array_elements(cv.contents) AS cvc
            )
            || setweight(to_tsvector(coalesce(description, '')), 'D')

            FROM ansible_collectionversion cv
        )
Actions #1

Updated by bmbouter over 4 years ago

It was working for the existing data tests that I tried. I had experienced this while developing and this caused me to add the string_agg("ansible_tag"."name", ' ') here

I can try to reproduce it against a collection I build with two tags. It would be great to have some fixture data or an export of some kind I could reproduce it with.

Actions #2

Updated by osapryki over 4 years ago

It is failing when more than one collection available, because there is no filter on SELECT subquery.
Fix is available https://github.com/pulp/pulp_ansible/pull/158

Actions #3

Updated by daviddavis over 4 years ago

  • Status changed from NEW to POST
  • Sprint set to Sprint 57

Added by Alexander Saprykin over 4 years ago

Revision dd0e3b2e | View on GitHub

Fix update query in migration 0004_add_fulltext_search_indexes

https://pulp.plan.io/issues/5226 closes #5226

Actions #4

Updated by Anonymous over 4 years ago

  • Status changed from POST to MODIFIED
Actions #5

Updated by bmbouter over 3 years ago

  • Status changed from MODIFIED to CLOSED - CURRENTRELEASE

Also available in: Atom PDF