Skip to content

Fix immutabledict error by avoiding pd.read_sql()#117

Merged
monodera merged 2 commits into
mainfrom
fix/fetch-query-immutabledict
Oct 7, 2025
Merged

Fix immutabledict error by avoiding pd.read_sql()#117
monodera merged 2 commits into
mainfrom
fix/fetch-query-immutabledict

Conversation

@monodera
Copy link
Copy Markdown
Contributor

@monodera monodera commented Oct 7, 2025

Summary

  • Replace pd.read_sql() with session.execute() in all fetch methods to avoid immutabledict compatibility issues
  • Previous fix (Fix immutabledict error in TargetDB fetch methods #116) only changed connection acquisition but pd.read_sql() itself was causing the error
  • Modified fetch_all(), fetch_by_id(), and fetch_query() to manually construct DataFrames from query results

Changes

  • fetch_all(): Use session.execute() and manually construct DataFrame
  • fetch_by_id(): Use session.execute() and manually construct DataFrame
  • fetch_query(): Use session.execute(text()) and manually construct DataFrame

Related

Fixes the root cause of immutabledict errors reported after #116

🤖 Generated with Claude Code

monodera and others added 2 commits October 7, 2025 08:52
Replace pd.read_sql() with session.execute() in all fetch methods
to avoid immutabledict compatibility issues with SQLAlchemy 2.x.
The previous fix only changed connection acquisition method but
pd.read_sql() itself was causing the immutabledict error.

Changes:
- fetch_all(): Use session.execute() and manually construct DataFrame
- fetch_by_id(): Use session.execute() and manually construct DataFrame
- fetch_query(): Use session.execute(text()) and manually construct DataFrame

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

Co-Authored-By: Claude <noreply@anthropic.com>
The previous fix didn't properly handle ORM query results. When using
select(model), the result rows contain model instances, not raw tuples.
This caused missing columns in the DataFrame (e.g., 'partner_name').

Changes:
- Use select() instead of session.query().statement for consistency
- Extract column names from model.__mapper__.columns
- Extract values from model instances using getattr() for each column
- This ensures all model attributes are properly captured in the DataFrame

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

Co-Authored-By: Claude <noreply@anthropic.com>
@monodera monodera merged commit d7cb8be into main Oct 7, 2025
1 check 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.

1 participant