Hey everybody
I have a weird issue regarding my custom app and fixtures and I hope someone might be able to help me.
The Setting
Reading through the documentation and a lot of posts in this forum, I came to the conclusion that create a Custom App
is the way to go for me. The basics are quite simple:
- there are a couple of
Custom Field
I need to add to some DocTypes belonging to the Stock and Buying Module of ERPNext - I need to create a couple of Suppliers, Item Groups, Item Variants and Items
- I want to make those changes portable and need to ability to install them in testing- and production-environments
So, working with bench export-fixtures
, I found out I probably need to filter my fixtures
inside hooks.py
. Because if I donāt do this, my exported json files contain a lot of stuff from other apps and module. Ok, here is the important part of my hooks.py
fixtures = [
"Address",
{
"doctype": "Supplier Group",
"filters": [["name", "in", [
"Primary Processor",
]]]
},
"Supplier",
{
"doctype": "Item Group",
"filters": [["name", "in", [
"Packaging",
"Plastics"
]]]
},
{
"doctype": "Item Attribute",
"filters": [["name", "in", [
"Material Form",
"Plastic Type"
]]]
},
"Item",
{
"doctype": "Custom Field",
"filters": {
"module": ["=", "Bestandsmeldung EBH"]
}
},
]
So far so good. Executing bench export-fixtures
created a couple of json files inside the fixtures
subfolder and they look good.
The Problem
However, when I try to install the app in another environment, I get strange error:
builtins.AttributeError: 'NoneType' object has no attribute 'lft'
So, what I have found out is, that his happens here:
File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 912, in fn
return method_object(*args, **kwargs)
self = <Item: MAT>
args = ()
kwargs = {}
method_object = <bound method Item.on_update of <Item: MAT>>
method = 'on_update'
File "/home/frappe/frappe-bench/apps/erpnext/erpnext/stock/doctype/item/item.py", line 124, in on_update
invalidate_cache_for_item(self)
self = <Item: MAT>
File "/home/frappe/frappe-bench/apps/erpnext/erpnext/stock/doctype/item/item.py", line 1134, in invalidate_cache_for_item
invalidate_cache_for(doc, doc.item_group)
doc = <Item: MAT>
File "/home/frappe/frappe-bench/apps/erpnext/erpnext/setup/doctype/item_group/item_group.py", line 203, in invalidate_cache_for
for d in get_parent_item_groups(item_group):
doc = <Item: MAT>
item_group = 'Plastics'
File "/home/frappe/frappe-bench/apps/erpnext/erpnext/setup/doctype/item_group/item_group.py", line 192, in get_parent_item_groups
(item_group.lft, item_group.rgt),
item_group_name = 'Plastics'
from_item = False
settings = <ECommerceSettings: E Commerce Settings>
base_nav_page = {'name': 'All Products', 'route': '/all-products'}
base_parents = [{'name': 'Home', 'route': '/'}, {'name': 'All Products', 'route': '/all-products'}]
item_group = None
builtins.AttributeError: 'NoneType' object has no attribute 'lft'
Apparently, bench
is importing my Item Template
MAT
and while doing this, it tries to āinvalidate a cacheā. For some reason, they need to query the Item Group
of my Item
MAT
. But, its Item Group
Plastics
hasnāt been imported yet. This import would be part of importing the file: item_group.json
.
So, the installation of my app broke, but somehow, if I try it again, bench
tells me the app has been installed already
Subsequently executing bench migrate
created the same error.
Workaround
But, what I was able to find out is, that things work out, if I manually manipulate the āorder of importsā by moving json files out and in the fixtures folder.
The Big Question
So, my question would be, is it possible to enable bench
to export and import everything in the correct order to prevent such errors?