30350n / inventree_part_import

CLI to import parts from suppliers like DigiKey, LCSC, Mouser, etc. to InvenTree
MIT License
24 stars 8 forks source link

Categories mapping ignores duplicate names from different paths #24

Open sle118 opened 3 months ago

sle118 commented 3 months ago

Don't mean to bombard you with corner cases, but I did some analysis on an issue I was having with the parts category schema that matches Digikey. There are cases where sub categories are assigned different paths. A good example of this is for Transistors, which exists under both Discrete Semiconductor Products/Transistors and Electronics/Transistors which contains some sub categories as well. When building the category map, it seems like the 2nd instance of Transistors is ignored, which causes some import errors down the road.

The issue happens here.

    for category in categories.values():
        if category.structural or category.ignore:
            continue
        for alias in category.aliases:
            category_map[alias] = category
        if category.name not in ignore:
            if category.name not in category_map:
                category_map[category.name] = category
            else:
                ignore.add(category.name)
                category_map.pop(category.name)

Given that the map is keyed by name rather than by path, this is not a simple fix. So in the meantime, I will rename my duplicate categories in InvenTree and add aliases if I ever import parts that match one of the renamed categories.

thank you!

30350n commented 3 months ago

Yeah, I could do something like checking parent category matches recursively if there's multiple matches (I considered this during implementation but ultimately decided against it). But tbh, this is an edge case that you don't really run into with any reasonable setup.

Importing the complete DigiKey category structure into InvenTree is just an awful idea.

sle118 commented 3 months ago

Importing the complete DigiKey category structure into InvenTree is just an awful idea.

lol. the idea of a newbe for using the InvenTree system. I am starting to realize this now but I have a good amount of data entered and a goal in mind so cleanup will wait. In the meantime I renamed the duplicates to get around the issue and will select them as aliases when importing parts in that given category. At least this will document the issue if someone was to stumble on the same problem

30350n commented 3 months ago

(Will keep this open, as it's still a bug, but I don't really have time to tackle this, thus the wontfix tag).