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
Avoid to use features that will be removed in SQLAlchemy v2.0 #4304
Avoid to use features that will be removed in SQLAlchemy v2.0 #4304
Conversation
Let me set this PR's milestone v3.1.0 since SQLAlchemy v2.0 will be released in January.
|
Codecov Report
@@ Coverage Diff @@
## master #4304 +/- ##
==========================================
- Coverage 89.77% 89.53% -0.24%
==========================================
Files 170 170
Lines 13265 13389 +124
==========================================
+ Hits 11908 11988 +80
- Misses 1357 1401 +44
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
try: | ||
from sqlalchemy.orm import declarative_base | ||
except ImportError: | ||
# TODO(c-bata): Remove this after dropping support for SQLAlchemy v1.3 or prior. | ||
from sqlalchemy.ext.declarative import declarative_base |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optuna/storages/_rdb/models.py:40
/Users/c-bata/go/src/github.com/optuna/optuna/optuna/storages/_rdb/models.py:40: MovedIn20Warning: Thedeclarative_base()
function is now available as sqlalchemy.orm.declarative_base(). (deprecated since: 1.4) (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
BaseModel: Any = declarative_base()
connection = self.engine.connect() | ||
context = alembic_migration.MigrationContext.configure(connection) | ||
with connection.begin(): | ||
script = self._create_alembic_script() | ||
context.stamp(script, revision) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests/storages_tests/rdb_tests/test_storage.py: 11 warnings
/Users/c-bata/go/src/github.com/optuna/optuna/optuna/storages/_rdb/storage.py:1103: RemovedIn20Warning: The current statement is being autocommitted using implicit autocommit, which will be removed in SQLAlchemy 2.0. Use the .begin() method of Engine or Connection in order to use an explicit transaction for DML and DDL statements. (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
context.stamp(script, revision)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Note] I confirmed that this logic worked with the following test case locally.
optuna/tests/storages_tests/rdb_tests/test_storage.py
Lines 139 to 142 in 4d06898
# TODO(ohta): Remove the following comment out when the second revision is introduced. | |
# with pytest.raises(RuntimeError): | |
# storage._set_alembic_revision(storage._version_manager._get_base_version()) | |
# storage._check_table_schema_compatibility() |
Maybe we can activate it in a follow-up PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
FYI: I pushed a temporary change to run tests with sqlalchemy 2.0.0rc2 at e57e151. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Thank you for your swift review. I'll revert e57e151 after reviewed by yanase-san 🙇 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By using optuna-e2e, I confirmed that the change in the migration scripts worked with SQLAlchemy==[1.3.0, 1.4.46, 2.0.0rc2]. (Actually mssql
did not worked with SQLAlchemy==1.3.0, but I don't think it is related to this PR.) LGTM!
@c-bata could you revert the tentative change in the CI settings?
connection = self.engine.connect() | ||
context = alembic_migration.MigrationContext.configure(connection) | ||
with connection.begin(): | ||
script = self._create_alembic_script() | ||
context.stamp(script, revision) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Note] I confirmed that this logic worked with the following test case locally.
optuna/tests/storages_tests/rdb_tests/test_storage.py
Lines 139 to 142 in 4d06898
# TODO(ohta): Remove the following comment out when the second revision is introduced. | |
# with pytest.raises(RuntimeError): | |
# storage._set_alembic_revision(storage._version_manager._get_base_version()) | |
# storage._check_table_schema_compatibility() |
Maybe we can activate it in a follow-up PR.
This reverts commit e57e151.
@toshihikoyanase Thank you for your review! I've just pushed 3d20af1 to revert the tentative change. |
I confirmed that the CI settings were reverted. Let me merge this PR. |
Motivation
CuPy team reported that Optuna depends on some SQLAlchemy's features that will be removed in the SQLAlchemy 2.0 release.
cupy/cupy#7276
Description of the changes
Fix warnings of
sqlalchemy.exc.RemovedIn20Warning
. We can detect them like: