Skip to content

Conversation

@cfsmp3
Copy link
Contributor

@cfsmp3 cfsmp3 commented Jan 4, 2026

Summary

This PR upgrades SQLAlchemy to version 2.0.45, addressing the breaking changes from the major version update. This is an equivalent replacement for PR #959 (Dependabot's auto-generated PR) but with the necessary code changes to make all tests pass.

Changes made:

  • DeclarativeBase update: Replace deprecated declarative_base() with new class-based DeclarativeBase pattern
  • Raw SQL execution: Wrap string SQL with text() in mod_health/controllers.py and tests/base.py
  • DeclEnumType fix: Use String(50) as impl instead of Enum to avoid SQLAlchemy 2.0's stricter enum value validation in TypeDecorator
  • Engine creation: Remove deprecated convert_unicode parameter and use StaticPool for SQLite in-memory databases to ensure proper connection sharing during tests
  • Type hints: Use generic Dialect type instead of SQLite-specific dialect types

Test plan

  • All 402 tests pass with the upgraded SQLAlchemy version
  • Verify application works correctly in staging environment

🤖 Generated with Claude Code

database.py Outdated
return DeclEnumType(self.enum)

def process_bind_param(self, value: EnumSymbol, dialect: SQLiteDialect_pysqlite) -> str:
def process_bind_param(self, value: Optional[Any], dialect: Dialect) -> Optional[str]:
Copy link
Member

Choose a reason for hiding this comment

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

Why change this from EnumSymbol to an Optional[Any]?

database.py Outdated
return value.value

def process_result_value(self, value: str, dialect: SQLiteDialect_pysqlite) -> EnumSymbol:
def process_result_value(self, value: Optional[Any], dialect: Dialect) -> Optional[EnumSymbol]:
Copy link
Member

Choose a reason for hiding this comment

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

Same here, why replace a str (which value should clearly be) with Any, that even can be null

@cfsmp3 cfsmp3 force-pushed the chore/sqlalchemy-2.0-upgrade-fix branch 3 times, most recently from b67f6a9 to a99d38a Compare January 4, 2026 11:33
@cfsmp3
Copy link
Contributor Author

cfsmp3 commented Jan 4, 2026

Fixed the type annotations - restored EnumSymbol and str types instead of using Any. The original types were more specific and provide better type safety. Thanks for catching this!

cfsmp3 and others added 2 commits January 4, 2026 12:58
This PR upgrades SQLAlchemy to version 2.0.45, addressing breaking changes:

- Update DeclarativeBase: Replace deprecated declarative_base() with new
  class-based DeclarativeBase pattern
- Fix raw SQL execution: Wrap string SQL with text() in mod_health and tests
- Update DeclEnumType: Use String(50) as impl instead of Enum to avoid
  SQLAlchemy 2.0's stricter enum value validation in TypeDecorator
- Fix engine creation: Remove deprecated convert_unicode parameter and
  use StaticPool for SQLite in-memory databases to ensure connection sharing
- Update type hints: Use generic Dialect type instead of SQLite-specific

All 402 tests pass with the upgraded SQLAlchemy version.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Keep EnumSymbol and str types instead of Any for better type safety.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@canihavesomecoffee canihavesomecoffee force-pushed the chore/sqlalchemy-2.0-upgrade-fix branch from d382165 to c901650 Compare January 4, 2026 11:58
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 4, 2026

@canihavesomecoffee canihavesomecoffee merged commit 90f38d6 into master Jan 4, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants