#33256: Some schema tests don't clean up their tables
-------------------------------------+-------------------------------------
     Reporter:  Tim Graham           |                    Owner:  banani720
         Type:                       |                   Status:  assigned
  Cleanup/optimization               |
    Component:  Database layer       |                  Version:  dev
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  1                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Mohammad Ali Mehdizadeh):

 Replying to [ticket:33256 Tim Graham]:
 > Some test errors on a second consecutive run of `./tests/runtests.py
 --settings=test_postgres  --parallel=1 --keepdb schema` shows that some
 tests leave behind their tables. Attached is an initial patch for a couple
 of the cases.
 > {{{
 > ======================================================================
 > ERROR: test_add_foreign_key_quoted_db_table (schema.tests.SchemaTests)
 > ----------------------------------------------------------------------
 > Traceback (most recent call last):
 >   File "/home/tim/code/django/django/db/backends/utils.py", line 82, in
 _execute
 >     return self.cursor.execute(sql)
 > psycopg2.errors.DuplicateTable: relation "table_author_double_quoted"
 already exists
 >
 >
 > The above exception was the direct cause of the following exception:
 >
 > Traceback (most recent call last):
 >   File "/home/tim/code/django/django/test/utils.py", line 437, in inner
 >     return func(*args, **kwargs)
 >   File "/home/tim/code/django/django/test/testcases.py", line 1305, in
 skip_wrapper
 >     return test_func(*args, **kwargs)
 >   File "/home/tim/code/django/tests/schema/tests.py", line 3229, in
 test_add_foreign_key_quoted_db_table
 >     editor.create_model(Author)
 >   File "/home/tim/code/django/django/db/backends/base/schema.py", line
 355, in create_model
 >     self.execute(sql, params or None)
 >   File "/home/tim/code/django/django/db/backends/base/schema.py", line
 151, in execute
 >     cursor.execute(sql, params)
 >   File "/home/tim/code/django/django/db/backends/utils.py", line 66, in
 execute
 >     return self._execute_with_wrappers(sql, params, many=False,
 executor=self._execute)
 >   File "/home/tim/code/django/django/db/backends/utils.py", line 75, in
 _execute_with_wrappers
 >     return executor(sql, params, many, context)
 >   File "/home/tim/code/django/django/db/backends/utils.py", line 84, in
 _execute
 >     return self.cursor.execute(sql, params)
 >   File "/home/tim/code/django/django/db/utils.py", line 90, in __exit__
 >     raise dj_exc_value.with_traceback(traceback) from exc_value
 >   File "/home/tim/code/django/django/db/backends/utils.py", line 82, in
 _execute
 >     return self.cursor.execute(sql)
 > django.db.utils.ProgrammingError: relation "table_author_double_quoted"
 already exists
 >
 >
 > ======================================================================
 > ERROR: test_add_foreign_object (schema.tests.SchemaTests)
 > ----------------------------------------------------------------------
 > Traceback (most recent call last):
 >   File "/home/tim/code/django/django/db/backends/utils.py", line 82, in
 _execute
 >     return self.cursor.execute(sql)
 > psycopg2.errors.DuplicateTable: relation "schema_bookforeignobj" already
 exists
 >
 >
 > The above exception was the direct cause of the following exception:
 >
 > Traceback (most recent call last):
 >   File "/home/tim/code/django/tests/schema/tests.py", line 3238, in
 test_add_foreign_object
 >     editor.create_model(BookForeignObj)
 >   File "/home/tim/code/django/django/db/backends/base/schema.py", line
 355, in create_model
 >     self.execute(sql, params or None)
 >   File "/home/tim/code/django/django/db/backends/base/schema.py", line
 151, in execute
 >     cursor.execute(sql, params)
 >   File "/home/tim/code/django/django/db/backends/utils.py", line 66, in
 execute
 >     return self._execute_with_wrappers(sql, params, many=False,
 executor=self._execute)
 >   File "/home/tim/code/django/django/db/backends/utils.py", line 75, in
 _execute_with_wrappers
 >     return executor(sql, params, many, context)
 >   File "/home/tim/code/django/django/db/backends/utils.py", line 84, in
 _execute
 >     return self.cursor.execute(sql, params)
 >   File "/home/tim/code/django/django/db/utils.py", line 90, in __exit__
 >     raise dj_exc_value.with_traceback(traceback) from exc_value
 >   File "/home/tim/code/django/django/db/backends/utils.py", line 82, in
 _execute
 >     return self.cursor.execute(sql)
 > django.db.utils.ProgrammingError: relation "schema_bookforeignobj"
 already exists
 >
 >
 > ======================================================================
 > ERROR: test_remove_db_index_doesnt_remove_custom_indexes
 (schema.tests.SchemaTests)
 > Changing db_index to False doesn't remove indexes from Meta.indexes.
 > ----------------------------------------------------------------------
 > Traceback (most recent call last):
 >   File "/home/tim/code/django/django/db/backends/utils.py", line 82, in
 _execute
 >     return self.cursor.execute(sql)
 > psycopg2.errors.DuplicateTable: relation "schema_authorwithindexedname"
 already exists
 >
 >
 > The above exception was the direct cause of the following exception:
 >
 > Traceback (most recent call last):
 >   File "/home/tim/code/django/tests/schema/tests.py", line 2659, in
 test_remove_db_index_doesnt_remove_custom_indexes
 >     editor.create_model(AuthorWithIndexedName)
 >   File "/home/tim/code/django/django/db/backends/base/schema.py", line
 355, in create_model
 >     self.execute(sql, params or None)
 >   File "/home/tim/code/django/django/db/backends/base/schema.py", line
 151, in execute
 >     cursor.execute(sql, params)
 >   File "/home/tim/code/django/django/db/backends/utils.py", line 66, in
 execute
 >     return self._execute_with_wrappers(sql, params, many=False,
 executor=self._execute)
 >   File "/home/tim/code/django/django/db/backends/utils.py", line 75, in
 _execute_with_wrappers
 >     return executor(sql, params, many, context)
 >   File "/home/tim/code/django/django/db/backends/utils.py", line 84, in
 _execute
 >     return self.cursor.execute(sql, params)
 >   File "/home/tim/code/django/django/db/utils.py", line 90, in __exit__
 >     raise dj_exc_value.with_traceback(traceback) from exc_value
 >   File "/home/tim/code/django/django/db/backends/utils.py", line 82, in
 _execute
 >     return self.cursor.execute(sql)
 > django.db.utils.ProgrammingError: relation
 "schema_authorwithindexedname" already exists
 >
 >
 > ======================================================================
 > ERROR: test_remove_field_unique_does_not_remove_meta_constraints
 (schema.tests.SchemaTests)
 > ----------------------------------------------------------------------
 > Traceback (most recent call last):
 >   File "/home/tim/code/django/django/db/backends/utils.py", line 82, in
 _execute
 >     return self.cursor.execute(sql)
 > psycopg2.errors.DuplicateTable: relation "schema_authorwithuniquename"
 already exists
 >
 >
 > The above exception was the direct cause of the following exception:
 >
 > Traceback (most recent call last):
 >   File "/home/tim/code/django/django/test/testcases.py", line 1305, in
 skip_wrapper
 >     return test_func(*args, **kwargs)
 >   File "/home/tim/code/django/tests/schema/tests.py", line 2057, in
 test_remove_field_unique_does_not_remove_meta_constraints
 >     editor.create_model(AuthorWithUniqueName)
 >   File "/home/tim/code/django/django/db/backends/base/schema.py", line
 355, in create_model
 >     self.execute(sql, params or None)
 >   File "/home/tim/code/django/django/db/backends/base/schema.py", line
 151, in execute
 >     cursor.execute(sql, params)
 >   File "/home/tim/code/django/django/db/backends/utils.py", line 66, in
 execute
 >     return self._execute_with_wrappers(sql, params, many=False,
 executor=self._execute)
 >   File "/home/tim/code/django/django/db/backends/utils.py", line 75, in
 _execute_with_wrappers
 >     return executor(sql, params, many, context)
 >   File "/home/tim/code/django/django/db/backends/utils.py", line 84, in
 _execute
 >     return self.cursor.execute(sql, params)
 >   File "/home/tim/code/django/django/db/utils.py", line 90, in __exit__
 >     raise dj_exc_value.with_traceback(traceback) from exc_value
 >   File "/home/tim/code/django/django/db/backends/utils.py", line 82, in
 _execute
 >     return self.cursor.execute(sql)
 > django.db.utils.ProgrammingError: relation "schema_authorwithuniquename"
 already exists
 >
 >
 > ======================================================================
 > ERROR: test_remove_index_together_does_not_remove_meta_indexes
 (schema.tests.SchemaTests)
 > ----------------------------------------------------------------------
 > Traceback (most recent call last):
 >   File "/home/tim/code/django/django/db/backends/utils.py", line 82, in
 _execute
 >     return self.cursor.execute(sql)
 > psycopg2.errors.DuplicateTable: relation
 "schema_authorwithindexednameandbirthday" already exists
 >
 >
 > The above exception was the direct cause of the following exception:
 >
 > Traceback (most recent call last):
 >   File "/home/tim/code/django/django/test/testcases.py", line 1305, in
 skip_wrapper
 >     return test_func(*args, **kwargs)
 >   File "/home/tim/code/django/tests/schema/tests.py", line 2554, in
 test_remove_index_together_does_not_remove_meta_indexes
 >     editor.create_model(AuthorWithIndexedNameAndBirthday)
 >   File "/home/tim/code/django/django/db/backends/base/schema.py", line
 355, in create_model
 >     self.execute(sql, params or None)
 >   File "/home/tim/code/django/django/db/backends/base/schema.py", line
 151, in execute
 >     cursor.execute(sql, params)
 >   File "/home/tim/code/django/django/db/backends/utils.py", line 66, in
 execute
 >     return self._execute_with_wrappers(sql, params, many=False,
 executor=self._execute)
 >   File "/home/tim/code/django/django/db/backends/utils.py", line 75, in
 _execute_with_wrappers
 >     return executor(sql, params, many, context)
 >   File "/home/tim/code/django/django/db/backends/utils.py", line 84, in
 _execute
 >     return self.cursor.execute(sql, params)
 >   File "/home/tim/code/django/django/db/utils.py", line 90, in __exit__
 >     raise dj_exc_value.with_traceback(traceback) from exc_value
 >   File "/home/tim/code/django/django/db/backends/utils.py", line 82, in
 _execute
 >     return self.cursor.execute(sql)
 > django.db.utils.ProgrammingError: relation
 "schema_authorwithindexednameandbirthday" already exists
 >
 >
 > ======================================================================
 > ERROR: test_remove_unique_together_does_not_remove_meta_constraints
 (schema.tests.SchemaTests)
 > ----------------------------------------------------------------------
 > Traceback (most recent call last):
 >   File "/home/tim/code/django/django/db/backends/utils.py", line 82, in
 _execute
 >     return self.cursor.execute(sql)
 > psycopg2.errors.DuplicateTable: relation
 "schema_authorwithuniquenameandbirthday" already exists
 >
 >
 > The above exception was the direct cause of the following exception:
 >
 > Traceback (most recent call last):
 >   File "/home/tim/code/django/django/test/testcases.py", line 1305, in
 skip_wrapper
 >     return test_func(*args, **kwargs)
 >   File "/home/tim/code/django/tests/schema/tests.py", line 2176, in
 test_remove_unique_together_does_not_remove_meta_constraints
 >     editor.create_model(AuthorWithUniqueNameAndBirthday)
 >   File "/home/tim/code/django/django/db/backends/base/schema.py", line
 355, in create_model
 >     self.execute(sql, params or None)
 >   File "/home/tim/code/django/django/db/backends/base/schema.py", line
 151, in execute
 >     cursor.execute(sql, params)
 >   File "/home/tim/code/django/django/db/backends/utils.py", line 66, in
 execute
 >     return self._execute_with_wrappers(sql, params, many=False,
 executor=self._execute)
 >   File "/home/tim/code/django/django/db/backends/utils.py", line 75, in
 _execute_with_wrappers
 >     return executor(sql, params, many, context)
 >   File "/home/tim/code/django/django/db/backends/utils.py", line 84, in
 _execute
 >     return self.cursor.execute(sql, params)
 >   File "/home/tim/code/django/django/db/utils.py", line 90, in __exit__
 >     raise dj_exc_value.with_traceback(traceback) from exc_value
 >   File "/home/tim/code/django/django/db/backends/utils.py", line 82, in
 _execute
 >     return self.cursor.execute(sql)
 > django.db.utils.ProgrammingError: relation
 "schema_authorwithuniquenameandbirthday" already exists
 >
 >
 > ======================================================================
 > ERROR: test_unique_name_quoting (schema.tests.SchemaTests)
 > ----------------------------------------------------------------------
 > Traceback (most recent call last):
 >   File "/home/tim/code/django/django/db/backends/utils.py", line 84, in
 _execute
 >     return self.cursor.execute(sql, params)
 > psycopg2.errors.DuplicateTable: relation "unique-table" already exists
 >
 >
 > The above exception was the direct cause of the following exception:
 >
 > Traceback (most recent call last):
 >   File "/home/tim/code/django/tests/schema/tests.py", line 1978, in
 test_unique_name_quoting
 >     editor.alter_db_table(TagUniqueRename, old_table_name, 'unique-
 table')
 >   File "/home/tim/code/django/django/db/backends/base/schema.py", line
 474, in alter_db_table
 >     self.execute(self.sql_rename_table % {
 >   File "/home/tim/code/django/django/db/backends/base/schema.py", line
 151, in execute
 >     cursor.execute(sql, params)
 >   File "/home/tim/code/django/django/db/backends/utils.py", line 66, in
 execute
 >     return self._execute_with_wrappers(sql, params, many=False,
 executor=self._execute)
 >   File "/home/tim/code/django/django/db/backends/utils.py", line 75, in
 _execute_with_wrappers
 >     return executor(sql, params, many, context)
 >   File "/home/tim/code/django/django/db/backends/utils.py", line 84, in
 _execute
 >     return self.cursor.execute(sql, params)
 >   File "/home/tim/code/django/django/db/utils.py", line 90, in __exit__
 >     raise dj_exc_value.with_traceback(traceback) from exc_value
 >   File "/home/tim/code/django/django/db/backends/utils.py", line 84, in
 _execute
 >     return self.cursor.execute(sql, params)
 > django.db.utils.ProgrammingError: relation "unique-table" already exists
 > }}}


 I run the command but I can't produce errors, every thing works nice.

 {{{
 (django-venv) root@DESKTOP-N10114T:/mnt/d/mycode/django#
 ./tests/runtests.py --settings=test_postgres --parallel=1 --keepdb schema
 Testing against Django installed in '/mnt/d/mycode/django/django'
 Found 176 test(s).
 Using existing test database for alias 'default'...
 System check identified no issues (0 silenced).
 
.s................sss...s.ss.....s..ss.sss.s......ss.s......................s.............s.....................s..s....s...s.....................s.............s.....
 .s...s...s
 ----------------------------------------------------------------------
 Ran 176 tests in 11.057s

 OK (skipped=28)
 Preserving test database for alias 'default'...
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33256#comment:8>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107017f84699ce1-d8f92db6-62c0-4ae4-aa65-2e6f6a5b2ec5-000000%40eu-central-1.amazonses.com.

Reply via email to