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
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33256>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* Attachment "33256-init.diff" added.
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/33256#comment:1>
* owner: nobody => banani720
* status: new => assigned
Comment:
[]
--
Ticket URL: <https://code.djangoproject.com/ticket/33256#comment:2>
Comment (by banani720):
If I have not done all of the cases yet, but just want to check in to see
if I am going about this the correct way, should I still submit a pr? I've
added a `try-finally` clauses to a couple of the test cases that are
mentioned in the error log. This is my first time contributing to an open-
source and the tutorial isn't quite clear how I should handle a situation
like this. Any guidance would be appreciated.
--
Ticket URL: <https://code.djangoproject.com/ticket/33256#comment:3>
Comment (by Mariusz Felisiak):
> If I have not done all of the cases yet, but just want to check in to
see if I am going about this the correct way, should I still submit a pr?
I don't think there is a need to submit PR at this stage. You should be
able to [https://docs.djangoproject.com/en/3.2/internals/contributing
/writing-code/unit-tests/ run tests locally] and check that all `schema`
tests work:
{{{
./runtests.py --settings=test_postgres --parallel=1 --keepdb schema
}}}
I'd submit PR when all test pass.
--
Ticket URL: <https://code.djangoproject.com/ticket/33256#comment:4>
Comment (by Ayush Joshi):
Replying to [comment:4 Mariusz Felisiak]:
> > If I have not done all of the cases yet, but just want to check in to
see if I am going about this the correct way, should I still submit a pr?
>
> I don't think there is a need to submit PR at this stage. You should be
able to [https://docs.djangoproject.com/en/3.2/internals/contributing
/writing-code/unit-tests/ run tests locally] and check that all `schema`
tests work:
> {{{
> ./runtests.py --settings=test_postgres --parallel=1 --keepdb schema
> }}}
> I'd submit PR when all test pass.
When I run this command I don't know why but I'm getting the following
{{{ModuleNotFoundError}}}, could you please help?
{{{
Testing against Django installed in '/Python/django/django'
Traceback (most recent call last):
File "./runtests.py", line 657, in <module>
failures = django_tests(
File "./runtests.py", line 348, in django_tests
test_labels, state = setup_run_tests(verbosity, start_at, start_after,
test_labels)
File "./runtests.py", line 278, in setup_run_tests
test_modules, state = setup_collect_tests(start_at, start_after,
test_labels=test_labels)
File "./runtests.py", line 193, in setup_collect_tests
'INSTALLED_APPS': settings.INSTALLED_APPS,
File "/Python/django/django/conf/__init__.py", line 89, in __getattr__
self._setup(name)
File "/Python/django/django/conf/__init__.py", line 76, in _setup
self._wrapped = Settings(settings_module)
File "/Python/django/django/conf/__init__.py", line 184, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in
import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 973, in
_find_and_load_unlocked
ModuleNotFoundError: No module named 'test_postgres'
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33256#comment:5>
Comment (by Mariusz Felisiak):
Replying to [comment:5 Ayush Joshi]:
> When I run this command I don't know why but I'm getting the following
{{{ModuleNotFoundError}}}, could you please help?
`--settings` should be a path to your `settings` (see
[https://docs.djangoproject.com/en/4.0/internals/contributing/writing-code
/unit-tests/#using-another-settings-module docs]) not a test module. If
you're having trouble understanding how Django works, see
TicketClosingReasons/UseSupportChannels for ways to get help.
--
Ticket URL: <https://code.djangoproject.com/ticket/33256#comment:6>
Comment (by Mohammad Ali Mehdizadeh):
Can I work on this ticket please?
--
Ticket URL: <https://code.djangoproject.com/ticket/33256#comment:7>
Comment (by Mohammad Ali Mehdizadeh):
Replying to [ticket:33256 Tim Graham]:
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>
Comment (by Tim Graham):
Have you run the command a second time so that you're reusing an existing
database?
--
Ticket URL: <https://code.djangoproject.com/ticket/33256#comment:9>
* owner: banani720 => Mohammad Ali Mehdizadeh
--
Ticket URL: <https://code.djangoproject.com/ticket/33256#comment:10>
Comment (by Mohammad Ali Mehdizadeh):
Replying to [comment:9 Tim Graham]:
> Have you run the command a second time so that you're reusing an
existing database?
No, I use a new instance of postgres and I check the databases and remove
''test_'' database each time.
But I can't produce errors.
--
Ticket URL: <https://code.djangoproject.com/ticket/33256#comment:11>
Comment (by Mohammad Ali Mehdizadeh):
This is my test_postgres.py file:
{{{
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'USER': 'postgres_user',
'PASSWORD': 'postgres_password',
'HOST': 'postgres_host',
'PORT': 'postgres_port',
},
'other': {
'ENGINE': 'django.db.backends.postgresql',
'USER': 'postgres_user',
'PASSWORD': 'postgres_password',
'HOST': 'postgres_host',
'PORT': 'postgres_port',
},
}
SECRET_KEY = "django_tests_secret_key"
# Use a fast hasher to speed up tests.
PASSWORD_HASHERS = [
"django.contrib.auth.hashers.MD5PasswordHasher",
]
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
USE_TZ = False
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33256#comment:12>
Comment (by Tim Graham):
The errors happen on a second consecutive test run (and don't remove the
existing database between test runs).
--
Ticket URL: <https://code.djangoproject.com/ticket/33256#comment:13>
Comment (by Mohammad Ali Mehdizadeh):
Thank you for guidance, I create the same error.
So have you any idea how to solve this issue?
--
Ticket URL: <https://code.djangoproject.com/ticket/33256#comment:14>
Comment (by Mohammad Ali Mehdizadeh):
Replying to [comment:13 Tim Graham]:
Thank you for guidance, I create the same error.
So have you any idea how to solve this issue?
--
Ticket URL: <https://code.djangoproject.com/ticket/33256#comment:15>
Comment (by Tim Graham):
I attached an initial patch to this ticket. You should apply similar
techniques to other tests.
--
Ticket URL: <https://code.djangoproject.com/ticket/33256#comment:16>
Comment (by Mohammad Ali Mehdizadeh):
Replying to [comment:16 Tim Graham]:
Do you have any idea, how to write a test for this scenario.
--
Ticket URL: <https://code.djangoproject.com/ticket/33256#comment:17>
Comment (by Tim Graham):
You only need to fix the existing errors. No additional tests are needed.
--
Ticket URL: <https://code.djangoproject.com/ticket/33256#comment:18>
* has_patch: 0 => 1
Comment:
I create a PR [https://github.com/django/django/pull/15528]
feel free to feedback me
--
Ticket URL: <https://code.djangoproject.com/ticket/33256#comment:19>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/33256#comment:20>
* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/33256#comment:21>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"4b66a5e61780416d8d99e61193f93dc3351caf2c" 4b66a5e6]:
{{{
#!CommitTicketReference repository=""
revision="4b66a5e61780416d8d99e61193f93dc3351caf2c"
Fixed #33256 -- Fixed schema test failures when using --keepdb.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33256#comment:22>