Skip to content

fix: UTF-8 encoding and DML support for app.py#4

Open
Cerco01 wants to merge 1 commit into
4GeeksAcademy:mainfrom
Cerco01:fix/app-encoding-and-dml-support-clean
Open

fix: UTF-8 encoding and DML support for app.py#4
Cerco01 wants to merge 1 commit into
4GeeksAcademy:mainfrom
Cerco01:fix/app-encoding-and-dml-support-clean

Conversation

@Cerco01
Copy link
Copy Markdown

@Cerco01 Cerco01 commented Apr 1, 2026

What and why

While completing the SQL analysis exercise I ran into two bugs in app.py that affect all students. I investigated the root cause
of each one and fixed them after finishing the exercise.

Changes in src/app.py

FIX 1 — UTF-8 encoding
The original open() call did not specify an encoding, so Python used the OS default (cp1252 on Windows). This caused the error:
charmap codec can't decode byte 0x8f
because queries.sql contains UTF-8 characters (accents, emojis).
Fix: added encoding='utf-8' explicitly to the open() call.

FIX 2 — DML support (INSERT, UPDATE, DELETE)
pd.read_sql() only handles SELECT statements, as it expects rows in return. For INSERT/UPDATE/DELETE it raised:
This result object does not return rows. It has been closed automatically.
Fix: detect the statement type and route DML operations to engine.begin() with sqlalchemy.text(), which handles transactions
correctly. SELECT statements continue using pd.read_sql().

Note

Both fixes are documented with inline comments in app.py explaining the original issue and the solution applied.

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