Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parsers: regex: check if regex from template is a string #450

Merged
merged 1 commit into from
Jan 25, 2023

Conversation

rmilecki
Copy link
Collaborator

Incorrectly formatted templates may result in passing OrderedDict as a
regex. That makes re.findall fail like:

  File "/home/foo/invoice2data/src/invoice2data/extract/parsers/regex.py", line 33, in parse
    matches = re.findall(regex, content)
  File "/usr/lib64/python3.6/re.py", line 222, in findall
    return _compile(pattern, flags).findall(string)
  File "/usr/lib64/python3.6/re.py", line 289, in _compile
    p, loc = _cache[type(pattern), pattern, flags]
TypeError: unhashable type: 'collections.OrderedDict'

Handle such case by displaying a meaningful warning.

@rmilecki
Copy link
Collaborator Author

I experienced this while trying to debug #441

Copy link
Collaborator

@bosd bosd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

Incorrectly formatted templates may result in passing OrderedDict as a
regex. That makes re.findall fail like:

  File "/home/foo/invoice2data/src/invoice2data/extract/parsers/regex.py", line 33, in parse
    matches = re.findall(regex, content)
  File "/usr/lib64/python3.6/re.py", line 222, in findall
    return _compile(pattern, flags).findall(string)
  File "/usr/lib64/python3.6/re.py", line 289, in _compile
    p, loc = _cache[type(pattern), pattern, flags]
TypeError: unhashable type: 'collections.OrderedDict'

Handle such case by displaying a meaningful warning.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
@rmilecki rmilecki merged commit ee6d900 into invoice-x:master Jan 25, 2023
@rmilecki rmilecki deleted the regex-str-check branch January 28, 2023 11:53
@rmilecki
Copy link
Collaborator Author

rmilecki commented Feb 3, 2023

This sould also help with #339

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.

None yet

2 participants