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

Fixed #33671 -- Added support for oracle alter collation on unique/indexed column #18049

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

mahigupta
Copy link

@mahigupta mahigupta commented Apr 5, 2024

Trac ticket number

ticket-33671

Branch description

Added support for alter collation in oracle on unique and indexed columns.

Checklist

  • This PR targets the main branch.
  • The commit message is written in past tense, mentions the ticket number, and ends with a period.
  • I have checked the "Has patch" ticket flag in the Trac system.
  • I have added or updated relevant tests.
  • I have added or updated relevant docs, including release notes if applicable.
  • For UI changes, I have attached screenshots in both light and dark modes.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello! Thank you for your contribution 💪

As it's your first contribution be sure to check out the patch review checklist.

If you're fixing a ticket from Trac make sure to set the "Has patch" flag and include a link to this PR in the ticket!

If you have any design or process questions then you can ask in the Django forum.

Welcome aboard ⛵️!

@mahigupta
Copy link
Author

buildbot, test on oracle.

@mahigupta
Copy link
Author

buildbot, test on oracle.

@mahigupta
Copy link
Author

Looks like Oracle used in buildbot do not support collation changes , hence my unit test skipped

 test_alter_unique_key_db_collation (schema.tests.SchemaTests.test_alter_unique_key_db_collation) ... skip (0.198s)

How we test it now ?

@nessita nessita changed the title Added support for oracle alter collation on unique/indexed column Fixed #33671 -- Added support for oracle alter collation on unique/indexed column Apr 5, 2024
@mahigupta
Copy link
Author

@ngnpope What you suggest for oracle ?

@nessita
Copy link
Contributor

nessita commented Apr 5, 2024

Looks like Oracle used in buildbot do not support collation changes , hence my unit test skipped

 test_alter_unique_key_db_collation (schema.tests.SchemaTests.test_alter_unique_key_db_collation) ... skip (0.198s)

How we test it now ?

I'm not an Oracle expert but could you please provide exact versions of the Oracle you are using or targeting?

@felixxm could you advice on this question considering you have the most expertise in integrating with Oracle? I checked your related PR #15642 and it is unclear to me how the Oracle tests were run for that PR.

@django django deleted a comment from mahigupta Apr 6, 2024
@felixxm
Copy link
Member

felixxm commented Apr 6, 2024

Looks like Oracle used in buildbot do not support collation changes , hence my unit test skipped

 test_alter_unique_key_db_collation (schema.tests.SchemaTests.test_alter_unique_key_db_collation) ... skip (0.198s)

How we test it now ?

It all depends on the database configuration, we are not able to test all possible Oracle configuration options. Do you have a local Oracle environment? This ticket is tricky and should be picked by someone who knows Oracle and have a local development environment to work on various configurations. Your patch doesn't fix the issue:

ERROR: test_alter_field_pk_fk_db_collation (migrations.test_operations.OperationTests)
AlterField operation of db_collation on primary keys changes any FKs
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/django/django/db/backends/utils.py", line 105, in _execute
    return self.cursor.execute(sql, params)
  File "/django/django/db/backends/oracle/base.py", line 572, in execute
    return self.cursor.execute(query, self._param_generator(params))
  File "/.virtualenvs/django-test-3.10/lib/python3.10/site-packages/oracledb/cursor.py", line 743, in execute
    impl.execute(self)
  File "src/oracledb/impl/thin/cursor.pyx", line 173, in oracledb.thin_impl.ThinCursorImpl.execute
  File "src/oracledb/impl/thin/protocol.pyx", line 425, in oracledb.thin_impl.Protocol._process_single_message
  File "src/oracledb/impl/thin/protocol.pyx", line 426, in oracledb.thin_impl.Protocol._process_single_message
  File "src/oracledb/impl/thin/protocol.pyx", line 419, in oracledb.thin_impl.Protocol._process_message
oracledb.exceptions.DatabaseError: ORA-43923: The column cannot be modified to the specified collation.
Help: https://docs.oracle.com/error-help/db/ora-43923/

@mahigupta
Copy link
Author

mahigupta commented Apr 6, 2024

As per https://docs.oracle.com/en/error-help/db/ora-43923/ Collation are divided into groups and
Group 1: BINARY, USING_NLS_COMP, USING_NLS_SORT, USING_NLS_SORT_CS, USING_NLS_SORT_VAR1, and USING_NLS_SORT_VAR1_CS
Group 2: BINARY_CI, USING_NLS_SORT_CI, and USING_NLS_SORT_VAR1_CI
Group 3: BINARY_AI, USING_NLS_SORT_AI, and USING_NLS_SORT_VAR1_AI
and action suggested by Oracle is
When modifying the column collation, specify a new collation that is in the same group as the current column collation. If there is no current collation, because you changed the column data type at the same time and the old data type is not a character data type, then select a collation from Group 1 as the new collation.

Reading this, should we really fix this or this is more of a user error and they should act accordingly?

@mahigupta
Copy link
Author

#18049 (comment)
Yes I didnt fix the issue when primary key has foreign key reference checks. But stil this patch can fix collation change on an inxdexed, unique column.
I will add test_alter_field_pk_fk_db_collation back to ignore test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants