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

chore: Rollback after each test, due to premature commit via remove_user_permission #29964

Merged
merged 2 commits into from
Feb 23, 2022

Conversation

marination
Copy link
Collaborator

Issue:

  • remove_user_permission in test_warehouse_user calls delete_doc that enqueues dynamic link deletion
  • Execution of background job eventually commits
  • While in the test suite it runs sequentially in the same thread and commits whatever was done until then
  • Which is why the rollback in tearDownClass is quite useless here
  • This premature commit causes many illegal transactions caught by assertRaises to be committed in the db
  • This creates faulty/dirty ledgers and breaks reports, as outiside the test suite this shouldn't/wouldn't happen

Eg:

  • test_serial_no_reqd creates a Serial No SLE without any Serial no in it, which is caught and asserted
  • The same would ideally be rolled back after TestStockEntry runs, but due to the premature commit, it did not
  • Such an SLE is illegal and ideally would not exist.
  • When reports try to compute using such an illegal SLE, they break because they cannot handle this illegal case.

Fix:

…user_permission`

- `remove_user_permission` in `test_warehouse_user` calls delete_doc that enqueues dynamic link deletion
- Execution of background job eventually commits
- While in the test suite it runs sequentially in the same thread and commits whatever was done until then
- Which is why the rollback in `tearDownClass` is quite useless here
- This premature commit causes many illegal transactions caught by `assertRaises` to be committed in the db
- This creates faulty/dirty ledgers and breaks reports, as outiside the test suite this shouldn't/wouldn't happen
- Rollback after each test, and for `test_warehouse_user` in particular, manually cancel transaction
@codecov
Copy link

codecov bot commented Feb 23, 2022

Codecov Report

Merging #29964 (5ff3705) into develop (856d3f6) will increase coverage by 0.03%.
The diff coverage is n/a.

@@             Coverage Diff             @@
##           develop   #29964      +/-   ##
===========================================
+ Coverage    59.65%   59.68%   +0.03%     
===========================================
  Files         1109     1109              
  Lines        69170    69167       -3     
===========================================
+ Hits         41261    41284      +23     
+ Misses       27909    27883      -26     
Impacted Files Coverage Δ
...em_wise_sales_register/item_wise_sales_register.py 51.81% <0.00%> (-9.55%) ⬇️
...unts/report/purchase_register/purchase_register.py 73.28% <0.00%> (-6.17%) ⬇️
...work_order_stock_report/work_order_stock_report.py 94.11% <0.00%> (-5.89%) ⬇️
...e_purchase_register/item_wise_purchase_register.py 75.00% <0.00%> (-4.00%) ⬇️
.../report/bom_operations_time/bom_operations_time.py 89.13% <0.00%> (-2.18%) ⬇️
erpnext/crm/doctype/prospect/prospect.py 55.22% <0.00%> (-1.50%) ⬇️
...e_commerce/variant_selector/item_variants_cache.py 77.46% <0.00%> (-1.41%) ⬇️
.../report/accounts_receivable/accounts_receivable.py 71.79% <0.00%> (-0.86%) ⬇️
erpnext/controllers/sales_and_purchase_return.py 84.84% <0.00%> (-0.76%) ⬇️
...ype/account/chart_of_accounts/chart_of_accounts.py 77.39% <0.00%> (-0.69%) ⬇️
... and 24 more

@marination marination merged commit 8b1ef7b into frappe:develop Feb 23, 2022
ankush pushed a commit that referenced this pull request Feb 23, 2022
…user_permission` (backport #29964) (#29967)

* chore: Rollback after each test, due to premature commit via `remove_user_permission`

- `remove_user_permission` in `test_warehouse_user` calls delete_doc that enqueues dynamic link deletion
- Execution of background job eventually commits
- While in the test suite it runs sequentially in the same thread and commits whatever was done until then
- Which is why the rollback in `tearDownClass` is quite useless here
- This premature commit causes many illegal transactions caught by `assertRaises` to be committed in the db
- This creates faulty/dirty ledgers and breaks reports, as outiside the test suite this shouldn't/wouldn't happen
- Rollback after each test, and for `test_warehouse_user` in particular, manually cancel transaction

(cherry picked from commit bf87437)

# Conflicts:
#	erpnext/stock/doctype/stock_entry/test_stock_entry.py

* test: Make Variant if absent in `test_variant_work_order`, keep test atomic

(cherry picked from commit 5ff3705)

* fix: Merge conflicts

Co-authored-by: marination <maricadsouza221197@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant