Skip to content

Conversation

@febus982
Copy link
Owner

@febus982 febus982 commented Jan 18, 2026

Code Improvements

This PR contains several minor code quality improvements:

  1. Remove duplicate license header - Removed duplicate partial MIT license block in _repository/abstract.py

  2. Remove unnecessary partial wrapper - The partial() wrapper in _filter_order_by was not needed since asc and desc can be referenced directly as callables

  3. Remove deprecated future=True engine option - This option is deprecated in SQLAlchemy 2.0 and is now the default behavior

  4. Remove redundant or [] fallback - In cursor_paginated_find, the list comprehension already produces a list, making the or [] fallback unnecessary

  5. Add exception handling to SessionHandler.__del__ - The scoped_session.remove() call could fail if the database connection is already closed during garbage collection. Wrapping in try/except with
    debug logging prevents errors during interpreter shutdown

  6. Use any() for more efficient model validation - Replaces list comprehension with any() generator expression to short-circuit on first invalid model instead of iterating all items

  7. Extract shared primary key utility function - Consolidates duplicated PK inspection logic from BaseRepository._model_pk() and result_presenters._pk_from_result_object() into a single
    get_model_pk_name() function in common.py

febus982 and others added 9 commits January 18, 2026 12:24
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The partial() wrapper was not needed since asc and desc can be
referenced directly as callables.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The future=True option is deprecated in SQLAlchemy 2.0 and is now
the default behavior.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The list comprehension already produces a list, making the or []
fallback unnecessary.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The scoped_session.remove() call could fail if the database connection
is already closed during garbage collection. Wrapping in try/except
with debug logging prevents errors during interpreter shutdown.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Replaces list comprehension with any() generator expression to
short-circuit on first invalid model instead of iterating all items.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Consolidates duplicated PK inspection logic from BaseRepository._model_pk()
and result_presenters._pk_from_result_object() into a single
get_model_pk_name() function in common.py.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Verifies that exceptions from scoped_session.remove() are caught
and logged during cleanup, preventing errors during garbage collection.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Use Callable instead of type since asc/desc are functions, not types.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@febus982 febus982 changed the title Other claude code improvements Other code improvements Jan 18, 2026
@febus982 febus982 marked this pull request as ready for review January 18, 2026 12:48
@febus982 febus982 merged commit 33c31ac into main Jan 18, 2026
11 checks passed
@febus982 febus982 deleted the improvements branch January 18, 2026 12:49
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.

2 participants