sqlalchemy / sqlalchemy/mako

Incorrect message when non-ascii char appears in template

Open
#258 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug lexer low priority
Dominant language
Python
Stars
459
Forks
90
PR merge metrics
No merged PRs in 30d

Description

Migrated issue, originally created by Glenn WIkle

You might think it is minor to have default values in an exception message but given that Mako is a parsing system, users need more help figuring out where the incorrect syntax is in their input files.

In the current version of lexer.py line 215 is this:

                  0, 0, filename)

i think the two zeros here result in the message which looks like

Unicode decode operation of encoding 'ascii' failed in file 'templates/summary.html' at line: 0 char: 0

So any non-ascii char anywhere in the input file template will generate this same message.

I spent quite a while looking for unprintable characters in my template at 0,0 before I dug into the code to find that the non-ascii character was really in a different position.

(Next I'll have to figure out why it's restricting the character set to ascii)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by inspecting lexer.py around line 215 and reproduce the failure using a template such as templates/summary.html containing a non-ASCII character. Trace how the parser determines the reported position and encoding failure. Done means the error identifies the relevant location instead of reporting line 0, char 0, with the intended encoding behavior clarified.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.