Fix immutabledict error by avoiding pd.read_sql()#117
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
pd.read_sql()withsession.execute()in all fetch methods to avoid immutabledict compatibility issuespd.read_sql()itself was causing the errorfetch_all(),fetch_by_id(), andfetch_query()to manually construct DataFrames from query resultsChanges
fetch_all(): Usesession.execute()and manually construct DataFramefetch_by_id(): Usesession.execute()and manually construct DataFramefetch_query(): Usesession.execute(text())and manually construct DataFrameRelated
Fixes the root cause of immutabledict errors reported after #116
🤖 Generated with Claude Code