Opened 15 years ago

Closed 14 years ago

#12201 closed (fixed)

django-admin.py makemessages could show the line number when it fails

Reported by: madewulf Owned by: nobody
Component: Internationalization Version: dev
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

For the following template file :

<p>{%blocktrans%}Dear {{worker}}{%blocktrans%}</p>

the command django-admin.py makemessages -lfr fails (because of the non closed blocktrans tag) without telling on which file it failed.

I just received the following, not very helpful, message :

Traceback (most recent call last):
  File "/usr/bin/django-admin.py", line 5, in <module>
    management.execute_from_command_line()
  File "/var/lib/python-support/python2.6/django/core/management/__init__.py", line 331, in execute_from_command_line
    utility.execute()
  File "/var/lib/python-support/python2.6/django/core/management/__init__.py", line 295, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/var/lib/python-support/python2.6/django/core/management/base.py", line 192, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/var/lib/python-support/python2.6/django/core/management/base.py", line 219, in execute
    output = self.handle(*args, **options)
  File "/var/lib/python-support/python2.6/django/core/management/commands/makemessages.py", line 232, in handle
    make_messages(locale, domain, verbosity, process_all, extensions)
  File "/var/lib/python-support/python2.6/django/core/management/commands/makemessages.py", line 149, in make_messages
    open(os.path.join(dirpath, thefile), "w").write(templatize(src))
  File "/var/lib/python-support/python2.6/django/utils/translation/__init__.py", line 100, in templatize
    return real_templatize(src)
  File "/var/lib/python-support/python2.6/django/utils/translation/trans_real.py", line 478, in templatize
    raise SyntaxError("Translation blocks must not include other block tags: %s" % t.contents)
SyntaxError: Translation blocks must not include other block tags: blocktrans

It would be more helpful to tell on which file the process failed, and if possible, at which line.

Attachments (4)

12201-1.diff (6.1 KB ) - added by Ramiro Morales 15 years ago.
A patch for this ticket. It changes Django templates Lexer.tokenize() to return a list of (token, lineno) tuples
12201-2.diff (6.2 KB ) - added by Ramiro Morales 15 years ago.
A slightly enhanced patch
12201-3.diff (8.3 KB ) - added by Claude Paroz 14 years ago.
Refreshed patch and test
12201-4.diff (6.8 KB ) - added by Claude Paroz 14 years ago.
Alternate patch which doesn't change Lexer API

Download all attachments as: .zip

Change History (12)

comment:1 by anonymous, 15 years ago

Summary: django-admin.py makemessages fail without telling on which file it faileddjango-admin.py makemessages fails without telling on which file it failed

by Ramiro Morales, 15 years ago

Attachment: 12201-1.diff added

A patch for this ticket. It changes Django templates Lexer.tokenize() to return a list of (token, lineno) tuples

comment:2 by Ramiro Morales, 15 years ago

Has patch: set
milestone: 1.2
Version: 1.0SVN

by Ramiro Morales, 15 years ago

Attachment: 12201-2.diff added

A slightly enhanced patch

comment:3 by Ramiro Morales, 15 years ago

It is strange you are aren't getting the file name in the error message because it was added back in April 2009 (r10538, #10234). Only explanation I can find is you are using some 1.0.x release.

I´ve taken it further to also show the line number but it needed some modifications to the inner parts of the Django templates Lexer. see attached patch.

comment:4 by Russell Keith-Magee, 15 years ago

Triage Stage: UnreviewedAccepted

comment:5 by Ramiro Morales, 15 years ago

milestone: 1.2
Summary: django-admin.py makemessages fails without telling on which file it faileddjango-admin.py makemessages could show the line number when it fails
  • Changing summary to describe only the feature suggestion (show line number where the error is located) made by the OP whose fate hasn't been decided yet, the other one (show the name of the file with problems) has been fixed in since 1.1.
  • Removing milestone 1.2 because this ticket doesn't meet the requirements at this stage of the release preparation process.

comment:6 by Ramiro Morales, 14 years ago

Needs documentation: set
Needs tests: set

by Claude Paroz, 14 years ago

Attachment: 12201-3.diff added

Refreshed patch and test

comment:7 by Claude Paroz, 14 years ago

Needs tests: unset

I updated the patch to apply again on trunk, and I added a test. Does this really need documentation?

by Claude Paroz, 14 years ago

Attachment: 12201-4.diff added

Alternate patch which doesn't change Lexer API

comment:8 by Ramiro Morales, 14 years ago

Resolution: fixed
Status: newclosed

(In [14813]) Fixed #12201 -- Added a lineno attibute to template Token so e.g. we can report line numbers in errors during i18n literals extraction. Thanks madewulf for the report and Claude Paroz for the patch.

Note: See TracTickets for help on using tickets.
Back to Top