Files in route give errors only when another route is active

103 views
Skip to first unread message

alessan...@gmail.com

unread,
Dec 7, 2022, 12:02:15 PM12/7/22
to Bots Open Source EDI Translator
Hello everyone,
I've encountered the strangest issue while setting up a system using bots.
This simple diagram illustrates my setup. setup.png
There are 2 routes. Either one works fine by itself. The grammars correctly validate the corresponding messages.
If, however, I activate both routes, the second one (bottom) fails with a bunch of errors in the input file. These errors lead me to believe that bots is using "csv grammar 1" to validate the input messages that should be in "csv grammar 2".
I know this description is vague, so I'm attaching a plugin that contains the minimum setup for the issue to occur.

Update:
I found a solution but advice would still be greatly appreciated.
The issue seems to arise from my definition of the csv grammars. Both of them import syntax and structure from a third file (refer to plugin archive). If I remove the third file and paste syntax and structure directly into both grammars, the problem is solved.

Before:
# mexal_csv.py
from bots.botsconfig import *

syntax = {
    ...
}

structure = [
    ...
]

# order_response_message_mexal_csv.py
from bots.botsconfig import *
from mexal_csv import syntax, structure # <--- The culprit

recorddefs = {
    ...
}

After:
# order_response_message_mexal_csv.py
from bots.botsconfig import *

syntax = {
    ...
}

structure = [
    ...
]

recorddefs = {
    ...
}

From reading the documentation and the example files, I was under the impression that this reuse of grammar parts was admissible. I think the documentation almost exactly covers this use case here where it says:
> A section can be reused/imported from another grammar file. Purpose: better maintenance of grammars. Example: edifact messages from a certain directory use the same recorddefs/segments:

> from recordsD96AUN import recorddefs

If this is not possible because of the issue in question, how may I reuse these parts of the grammar without duplication?

I know this is a handful so thank you for the attention.

Sincerely,
Alessandro Rubino

plugin_20221207.zip

Eppye Bots

unread,
Dec 9, 2022, 8:45:49 AM12/9/22
to bots...@googlegroups.com
main reason: complete nonsense in grammar.
please read documentation and examples provided.


kind regards, Henk-Jan Ebbers


--
You received this message because you are subscribed to the Google Groups "Bots Open Source EDI Translator" group.
To unsubscribe from this group and stop receiving emails from it, send an email to botsmail+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/botsmail/bcf554da-d71b-492f-977f-fe19d9958141n%40googlegroups.com.

alessan...@gmail.com

unread,
Dec 10, 2022, 11:01:46 AM12/10/22
to Bots Open Source EDI Translator
Hello Henk-Jan,
I realize my example plugin was probably too specific with my business logic and that may have led you to believe there was an error in my JSON grammars. In reality bots reported errors regarding one of the csv grammars. I took the liberty of modifying a plugin from the official ones to reproduce the error. If you install this plugin you can reproduce the error as such:
  1. Activate the route 1_csv2edi and run bots. Files are processed with no errors
  2. Deactivate the previous route and activate 2_edi2csv, run bots. Files are processed with no errors
  3. Activate both routes and run bots. Some of the files are now giving errors
Here is a screenshot of the errors
Untitled.png
As you can see, in the route 2_edi2csv, bots reports that the output grammar (csv_orders) has no fields "ORDERDATUM" or "ORDERNUMMER" and that it has mandatory fields "ALPHA1" and "REAL1". If you look at the grammar files you will find csv_orders does have those fields bots says it shouldn't have, while it's the other grammar, csv_other_grammar, that has the mandatory fields "ALPHA1" and "REAL1". Please disregard the mapping scripts as I have hardwired the values in just to exclude any issues from those.

This was just a follow-up to let you know what the issue really was and that I indeed do read the documentation and examples. At this time I have found a satisfactory solution, but I think the problem might stem from some confusion the bots engine makes when loading multiple grammars.

Kind regards,
Alessandro Rubino

alessan...@gmail.com

unread,
Dec 10, 2022, 11:05:17 AM12/10/22
to Bots Open Source EDI Translator
And of course I should have included the plugin I mentioned, here it is.
plugin_20221210.zip

Eppye Bots

unread,
Dec 11, 2022, 10:02:00 AM12/11/22
to bots...@googlegroups.com
not sure what I need to expect here.
I get lots of errors because of errors in grammars (fields not there, mandatory fields, nextmessageblock is not OK)
(please run with get_checklevel = 2 in bots.ini)
kind regards, Henk-Jan Ebbers


Eppye Bots

unread,
Dec 11, 2022, 10:29:42 AM12/11/22
to bots...@googlegroups.com
yes, I see.
you found a way to avoid this?

kind regards, Henk-Jan Ebbers


alessan...@gmail.com

unread,
Dec 12, 2022, 3:58:56 AM12/12/22
to Bots Open Source EDI Translator
I have found that exporting the grammar parts from functions solves this issue (bots 3.2.0).
Basically this

Before:
# csv_base.py
syntax = {
    'field_sep': ',',
    'quote_char':   '"',
    'charset':  "iso-8859-1",
    'noBOTSID': True,
}

# csv_orders.py
from csv_base import syntax, structure, nextmessageblock

After:
# csv_base.py
def get_syntax():
    return {
        'field_sep': ',',
        'quote_char':   '"',
        'charset':  "iso-8859-1",
        'noBOTSID': True,
    }
# csv_orders.py
from csv_base import get_syntax, get_structure, get_nextmessageblock

syntax, structure, nextmessageblock = get_syntax(), get_structure(), get_nextmessageblock()

I haven't looked much into the bots engine, so I can only guess why the problem happens. Maybe it reuses some object between runs with a stale value or maybe it creates a lookup table with a wrong key.

Sincerely,
Alessandro Rubino
Reply all
Reply to author
Forward
0 new messages