Skip to content

Don't set empty fields in output#456

Merged
rmilecki merged 1 commit intoinvoice-x:masterfrom
rmilecki:dont-set-empty-fields
Feb 1, 2023
Merged

Don't set empty fields in output#456
rmilecki merged 1 commit intoinvoice-x:masterfrom
rmilecki:dont-set-empty-fields

Conversation

@rmilecki
Copy link
Copy Markdown
Collaborator

Before introducing parsers concept extract() did not set empty fields in
output. So in case of re.findall() returning an empty list there was a
warning like:
WARNING:invoice2data.extract.invoice_template:regexp for field <foo> didn't match
and on <foo> in output dictionary / file.

That has unintentionally changed after commit 670f8729b7b6 ("Extend
fields syntax to support associative arrays & add 2 initial parsers
(#308)"). Output can now look like:
[
    {
        "issuer": "Company",
        "amount": 12.34,
        "date": "2023-01-01",
        "invoice_number": "01/2023",
        "test_field": [],
        "currency": "EUR",
        "desc": "Invoice from Company"
    }
]

Bring back old behaviour and don't set empty fields:
[
    {
        "issuer": "Company",
        "amount": 12.34,
        "date": "2023-01-01",
        "invoice_number": "01/2023",
        "currency": "EUR",
        "desc": "Invoice from Company"
    }
]

Before introducing parsers concept extract() did not set empty fields in
output. So in case of re.findall() returning an empty list there was a
warning like:
WARNING:invoice2data.extract.invoice_template:regexp for field <foo> didn't match
and on <foo> in output dictionary / file.

That has unintentionally changed after commit 670f872 ("Extend
fields syntax to support associative arrays & add 2 initial parsers
(invoice-x#308)"). Output can now look like:
[
    {
        "issuer": "Company",
        "amount": 12.34,
        "date": "2023-01-01",
        "invoice_number": "01/2023",
        "test_field": [],
        "currency": "EUR",
        "desc": "Invoice from Company"
    }
]

Bring back old behaviour and don't set empty fields:
[
    {
        "issuer": "Company",
        "amount": 12.34,
        "date": "2023-01-01",
        "invoice_number": "01/2023",
        "currency": "EUR",
        "desc": "Invoice from Company"
    }
]
@rmilecki
Copy link
Copy Markdown
Collaborator Author

I've just noticed that my old #308 changed parsing behaviour.

I'm wondering if the old behaviour made more sense and should be brought back. Any opinion on this?

@rmilecki rmilecki requested review from bosd and m3nu January 28, 2023 12:47
@bosd
Copy link
Copy Markdown
Collaborator

bosd commented Jan 29, 2023

I am kinda neutral on this. Both methods has his up and downsides.
But I tend to lean towards returning to the old behavior.

Copy link
Copy Markdown
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.

Let's restore the old behavior. :+1

@rmilecki rmilecki merged commit bc667cf into invoice-x:master Feb 1, 2023
@rmilecki rmilecki deleted the dont-set-empty-fields branch February 1, 2023 21:37
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.

2 participants