Not getting a filename while parsing through a '' file

There was an indentation error in my file due to which I was getting the following traceback -

We are getting File "<unknown>", why it is not able to get filename? This thing should be fixed so that it is easy to track in which file we are facing issue.

Check the stack trace: your “odoo” tools library is not passing a file to AST, therefore it cannot tell you a filename. This is nothing to do with Python; you should fix that library if you own it, or raise an issue if you don’t.

Because Odoo reads the source code into a string, maybe does some manipulation (such as trying to dedent the code using textwrap.dedent) and uses Python’s dynamic compilation tools (in the standard library (in this case, ast.literal_eval) to process the code.

I don’t use Odoo, but I guess that is supposed to be some kind of configuration file, and that Odoo is trying to read some text constants out of it. It could be that Odoo expects the file to have a specific format, and it is not allowed to just contain any Python code you want.

In any event, this is a support question for Odoo. You should check the Odoo documentation to make sure you understand what is expected in If what you have is supposed to work, you can file a bug report there (or look for an existing one). If the problem is in your (like it sounds like you’re saying), you can try to ask the Odoo developers to catch the exception and provide a nicer error message.

But Python cannot fix this, because it is not a problem in Python. It received code that was not in a source file, therefore it cannot tell you what source file it was based off of.

1 Like