Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server): TreeView lookup in DB should perform the same preperation operations … #26184

Conversation

fixundfertig123
Copy link
Contributor

@fixundfertig123 fixundfertig123 commented Apr 27, 2024

…as method update_nsm in file nestedset.py

Symptoms:
DB error when using tree view for custom doctypes, which names contain hyphens, underscores or spaces.

Reason:
Method "update_nsm" in file frappe/utils/nestedset.py builds SQL DB fields according to certain logic, see

parent_field = "parent_" + frappe.scrub(doc.doctype)

For frappe.scrub see:

frappe/frappe/__init__.py

Lines 1515 to 1517 in 71dfffa

def scrub(txt: str) -> str:
"""Return sluggified string. e.g. `Sales Order` becomes `sales_order`."""
return cstr(txt).replace(" ", "_").replace("-", "_").lower()

However, method "_get_children" in frappe/desk/treeview.py uses another methodology to lookup the data in the database, see

parent_field = "parent_" + doctype.lower().replace(" ", "_")

Example for different conversion:
Doctype name: "AAA-BBB-CCC"
method "update_nsm": "AAA-BBB-CCC" --> "parent_aaa_bbb_ccc"
method "_get_children": "AAA-BBB-CCC" --> "parent_aaa-bbb-ccc"

Resolution:
Updated method "_get_children" in frappe/desk/treeview.py to use same methodology of frappes "on-board resources".

Also created fix for ERPNext: See frappe/erpnext#41221

@fixundfertig123 fixundfertig123 requested a review from a team as a code owner April 27, 2024 20:59
@fixundfertig123 fixundfertig123 requested review from ankush and removed request for a team April 27, 2024 20:59
@github-actions github-actions bot added the add-test-cases Add test case to validate fix or enhancement label Apr 27, 2024
fixundfertig123 added a commit to fixundfertig123/erpnext that referenced this pull request Apr 28, 2024
@fixundfertig123 fixundfertig123 changed the title Bug fix TreeView: Lookup in DB should perform the same preperation operations … fix(server): TreeView lookup in DB should perform the same preperation operations … Apr 29, 2024
@fixundfertig123
Copy link
Contributor Author

Replaced by another pull

@fixundfertig123 fixundfertig123 deleted the feature/treeViewDBLookup branch April 29, 2024 09:41
@fixundfertig123 fixundfertig123 restored the feature/treeViewDBLookup branch April 29, 2024 09:42
@fixundfertig123
Copy link
Contributor Author

Replaced by another pull request to fix commit naming issues

@fixundfertig123 fixundfertig123 deleted the feature/treeViewDBLookup branch April 29, 2024 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
add-test-cases Add test case to validate fix or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant