codethesaur.us icon indicating copy to clipboard operation
codethesaur.us copied to clipboard

validatelanginfofiles crashes with AttributeError when "concepts" is not a JSON object

Open murainah opened this issue 3 weeks ago • 1 comments

Description

validatelanginfofiles is meant to report problems in language files as [Error] ... messages. But when a language file is valid JSON and its concepts value is not an object (for example a list), check_concepts raises an unhandled AttributeError instead of reporting a validation error.

Steps to reproduce

From the repo root, in python manage.py shell:

from pathlib import Path
from web.management.commands.validatelanginfofiles import Command

c = Command()
c.check_concepts({"concepts": []}, Path("langs/python/3/example.json"))

Actual result

File ".../web/management/commands/validatelanginfofiles.py", line 100, in check_concepts
    for concept_id, item_data in concepts.items():
AttributeError: 'list' object has no attribute 'items'

Reading the code, handle() calls validate_language_file(), which calls check_concepts(), so I expect python manage.py validatelanginfofiles to stop with a traceback on such a file instead of counting an error and continuing. I will confirm this at the command level in a regression test.

Expected result

An error message in the validator's usual style, and the command continues, for example:

[Error] `langs/python/3/example.json` has a `concepts` section that is not an object

Notes

The same assumption seems to exist for other non-object values: the top-level JSON value (data.get), meta (meta.get), and each entry inside concepts (item_data). I'd handle these in the same validator.

I'd like to work on this: following AGENTS.md, I'll add a failing test first in web/tests/test_commands.py and then a small fix. Could you assign me if that's OK?

Environment

  • Python 3.14.4, Django 6.1.1
  • Commit 7da649fc on main

murainah avatar Nov 08 '26 13:11 murainah

I've opened a PR for this: https://github.com/codethesaurus/codethesaur.us/pull/827. It covers the non-object concepts case with a regression test. Happy to extend it to the other non-object cases (top-level value, meta, concept entries) if you'd like.

murainah avatar Nov 08 '26 19:11 murainah