8000 fix: delete existing children first to avoid `UniqueValidationError` by sagarvora · Pull Request #24140 · frappe/frappe · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: delete existing children first to avoid UniqueValidationError #24140

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

Merged
merged 1 commit into from
Jan 8, 2024

Conversation

sagarvora
Copy link
Contributor

steps to replicate

> Create child table with a unique column
> Add values 1,2 to the unique column
> Try clearing all rows, and then adding values 2,3,4 to the unique column
> causes UniqueValidationError like so:

 File "apps/frappe/frappe/model/document.py", line 312, in save
    return self._save(*args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 365, in _save
    self.update_children()
  File "apps/frappe/frappe/model/document.py", line 397, in update_children
    self.update_child_table(df.fieldname, df)
  File "apps/frappe/frappe/model/document.py", line 406, in update_child_table
    d.db_update()
  File "apps/frappe/frappe/model/base_document.py", line 449, in db_update
    self.db_insert()
  File "apps/frappe/frappe/model/base_document.py", line 440, in db_insert
    self.show_unique_validation_message(e)
  File "apps/frappe/frappe/model/base_document.py", line 500, in show_unique_validation_message
    raise frappe.UniqueValidationError(self.doctype, self.name, e)
frappe.exceptions.UniqueValidationError: ('ABC VAT Code', '10c591d57e', IntegrityError(1062, "Duplicate entry '2' for key 'abc_id'"))

solution

delete existing rows first.

@sagarvora sagarvora requested review from a team and surajshetty3416 and removed request for a team January 5, 2024 05:22
@sagarvora sagarvora added backport version-14-hotfix backport to version 14 backport version-15-hotfix Backport the PR to v15 labels Jan 5, 2024
@ankush ankush removed the request for review from surajshetty3416 January 5, 2024 06:52
@ankush ankush self-assigned this Jan 5, 2024
@ankush
Copy link
Member
ankush commented Jan 5, 2024

Test failure is unrelated

@ankush ankush merged commit 417fce0 into frappe:develop Jan 8, 2024
mergify bot pushed a commit that referenced this pull request Jan 8, 2024
mergify bot pushed a commit that referenced this pull request Jan 8, 2024
…24140)

(cherry picked from commit 417fce0)

# Conflicts:
#	frappe/model/document.py
akhilnarang added a commit that referenced this pull request Jan 9, 2024
…-24140

fix: delete existing children first to avoid `UniqueValidationError` (backport #24140)
@sagarvora sagarvora deleted the delete-children-first branch January 9, 2024 11:56
frappe-pr-bot pushed a commit that referenced this pull request Jan 10, 2024
# [15.9.0](v15.8.1...v15.9.0) (2024-01-10)

### Bug Fixes

* added precision field in webform field ([3876ba2](3876ba2))
* added validation if upload is clicked without uploading file ([ba2ce30](ba2ce30))
* Allowed standard fields in data export ( creation, owner) (backport [#24187](#24187)) ([#24191](#24191)) ([5b66da4](5b66da4))
* broken `dynamic_link` to `link` formatting in query report (backport [#24054](#24054)) ([#24088](#24088)) ([4a9eae9](4a9eae9))
* Broken IMAP account disabling logic (backport [#24118](#24118)) ([#24131](#24131)) ([7669a7e](7669a7e))
* **communication:** don't change email case ([f91cff9](f91cff9))
* copy content on reply ([5135a13](5135a13))
* Correct logic for can_cancel ([#24196](#24196)) ([#24201](#24201)) ([94312f6](94312f6))
* delete existing children first to avoid `UniqueValidationError` ([#24140](#24140)) ([f00da85](f00da85))
* don't update docstatus (backport [#24216](#24216)) ([#24221](#24221)) ([b95f7c3](b95f7c3))
* **DX:** return email queue doc ([#23495](#23495)) ([#24174](#24174)) ([f25e42f](f25e42f))
* extract the frappe version from backup header directly ([4d2cf23](4d2cf23))
* get precision data while getting fields ([4cb65f0](4cb65f0))
* Handle empty value of datetime control ([cc3997d](cc3997d))
* include Web Form Field in core_doctypes ([785416a](785416a))
* **minor:** drop icon column, unsupported, fixes [#23826](#23826) ([a18c061](a18c061))
* **minor:** show footer on login via Website Settings, fixes [#24153](#24153) ([8a0b5c7](8a0b5c7))
* **minor:** Unpublish article when category is unpublished [#15361](#15361) ([c2c8323](c2c8323))
* mobile issue with form pop up ([#24125](#24125)) ([#24151](#24151)) ([de30760](de30760))
* notification.py should ignore permissions on fetching on mobile_no receiver list ([6f5535b](6f5535b))
* number card only gives integer ([#24047](#24047)) ([#24138](#24138)) ([16f9907](16f9907))
* **OTP:** Autofocus OTP input, fix placeholder ([#24203](#24203)) ([#24205](#24205)) ([458f3fc](458f3fc))
* **recorder:** Normalize `IN` in SQL queries ([#24132](#24132)) ([#24134](#24134)) ([9dc4d8f](9dc4d8f))
* **router:** Don't capture clicks on links with target attr ([#24110](#24110)) ([#24135](#24135)) ([b80de74](b80de74))
* Skip no-value fields for rename ([#24163](#24163)) ([#24164](#24164)) ([dfa2ffd](dfa2ffd))
* **style:** set min height correctly ([c774787](c774787))
* **test_recorder:** get the correct request ([#24143](#24143)) ([#24149](#24149)) ([9fa7e9f](9fa7e9f))
* use correct parent field in rebuild_tree() ([#24107](#24107)) ([#24121](#24121)) ([f12f9db](f12f9db))
* **Web Form:** make button label translatable ([#24122](#24122)) ([14ee9c8](14ee9c8))
* webhook error logging fails ([#24172](#24172)) ([#24183](#24183)) ([6cd7eba](6cd7eba))

### Features

* support background jobs in recorder ([1eb3a56](1eb3a56))

### Performance Improvements

* Update roles affected by role profile in background ([#24104](#24104)) ([840f059](840f059))
sagarvora added a commit that referenced this pull request Jan 12, 2024
…(backport #24140)

Co-authored-by: Sagar Vora <sagar@resilient.tech>
frappe-pr-bot pushed a commit that referenced this pull request Jan 16, 2024
## [14.62.3](v14.62.2...v14.62.3) (2024-01-16)

### Bug Fixes

* add a check for `gpg` existing ([db2fb36](db2fb36))
* collapse sidebar on picking workspace ([#24312](#24312)) ([#24313](#24313)) ([898c803](898c803))
* delete existing children first to avoid `UniqueValidationError` (backport [#24140](#24140)) ([0363371](0363371))
* don't update docstatus (backport [#24216](#24216)) ([#24220](#24220)) ([6d4dcf9](6d4dcf9))
* Error when displaying dashboard with number card using average and sum methods ([#24244](#24244)) ([7d75ed3](7d75ed3))
* Handle edge case while searching in current context ([b4d23ed](b4d23ed))
* include workspaces without domain restriction ([90d4734](90d4734))
* **minor:** add optional chaining for this.$input ([#24339](#24339)) ([65a642f](65a642f))
* **minor:** check if markdown_preview exists ([#24335](#24335)) ([8fbda2c](8fbda2c))
* **minor:** increase rate limit for web form ([#24295](#24295)) ([#24296](#24296)) ([49ddaa0](49ddaa0))
* misc (backport [#24303](#24303)) ([#24304](#24304)) ([bd3f89b](bd3f89b))
* mobile sidebar disappearing ([#24316](#24316)) ([#24341](#24341)) ([b5811b5](b5811b5))
* **mobile-ui:** tabs should scroll instead of stack (backport [#24309](#24309)) ([#24310](#24310)) ([5db8d08](5db8d08))
* **MultiCheck:** Use df.sort_options to enable/disable sort ([#24202](#24202)) ([#24290](#24290)) ([1aa1de2](1aa1de2))
* pass parent doctype on dashboard chart ([#24236](#24236)) ([#24237](#24237)) ([e9c10f4](e9c10f4))
* print perm check logs from DB query (backport [#24263](#24263)) ([#24267](#24267)) ([ce9fd66](ce9fd66))
* remove unknown column `indicator_color` ([8f6be35](8f6be35))
* **response:** fixup non-ASCII character filenames ([9dc059b](9dc059b))
* set correct recipient when reply to own email ([#24256](#24256)) ([#24259](#24259)) ([97fea1f](97fea1f))
* strip html instead of escaping when creating/updating workspace (backport [#24284](#24284)) ([8207559](8207559))
* **UX:** show status indicator in moblie view ([#24306](#24306)) ([#24307](#24307)) ([d74b5fc](d74b5fc))

### Reverts

* Revert "fix(Data Import): show failed import logs" ([56c9383](56c9383))
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport version-14-hotfix backport to version 14 backport version-15-hotfix Backport the PR to v15
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0