Frappe Exception: MandatoryError during frappe.get_doc

Hello everyone

In reference to my last thread, I’m faced with a new type of error I have yet to resolve.

So, assuming I have an Article with Number 101 under the Item Group “Clocks”. I’d like to give it the subgroup “Alarm”. This particular subgroup is already part of the Item Group Tree and is a part of “Clocks”.
This is currently in the system. Now on to add “Alarm” to the subgroup I would do this:

doc = frappe.get_doc(
        {
            "doctype":"Item",
            "item_code":"101"
            "item_subgroups": frappe.get_doc({"doctype":"Item Group", "item_group_name": "Alarm")})
        })
print(doc.item_subgroups.item_group_name) \\\ Returns "Alarm"
doc.save()

This however, throws this error:

frappe.exceptions.MandatoryError: [Item, 101]: item_group

So I was wondering what did I do wrong? I cannot directly enter a String, because “item_subgroups” expects an object (namely, an object from “item_group”) I feel it’s something simple that I’ve overlooked.

Kind regards,
Val

Okay, I managed to solve this problem on my own. The Problem here is, that “item_subgroups” needs a list for some reason, as it accesses another doctype in the database.

The correct code would look like this

doc = frappe.get_doc(
        {
            "doctype":"Item",
            "item_code":"101"
            "item_subgroups": {[subgroup: "Alarm"]}
        })

However, this makes it impossible to print this specific value into something that makes sense. An object will always be returned, and it can’t be accessed with “doc.item_subgroups.subgroup”, that will just return an error.