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: Renaming when doctype is used as a virtual link docfield fails #26025

Merged
merged 4 commits into from
Apr 23, 2024

Conversation

kareemk
Copy link
Contributor

@kareemk kareemk commented Apr 17, 2024

Reproduction steps:

  • Create a doctype "A"
  • Create another doctype "B" with a virtual link docfield with the option set to "A"
  • Create a document of type "A"
  • Attempt to rename document of type "A"

Stacktrace:

Traceback (most recent call last):
  File "apps/frappe/frappe/model/document.py", line 1658, in execute_action
    getattr(doc, __action)(**kwargs)
  File "apps/frappe/frappe/model/document.py", line 1040, in _rename
    self.name = rename_doc(doc=self, new=name, merge=merge, force=force, validate=validate_rename)
  File "apps/frappe/frappe/model/rename_doc.py", line 182, in rename_doc
    update_link_field_values(link_fields, old, new, doctype)
  File "apps/frappe/frappe/model/rename_doc.py", line 441, in update_link_field_values
    frappe.db.set_value(parent, {docfield: old}, docfield, new, update_modified=False)
  File "apps/frappe/frappe/database/database.py", line 994, in set_value
    query.run(debug=debug)
  File "apps/frappe/frappe/query_builder/utils.py", line 87, in execute_query
    result = frappe.db.sql(query, params, *args, **kwargs)  # nosemgrep
  File "apps/frappe/frappe/database/database.py", line 234, in sql
    self._cursor.execute(query, values)
  File "env/lib/python3.10/site-packages/pymysql/cursors.py", line 153, in execute
    result = self._query(query)
  File "env/lib/python3.10/site-packages/pymysql/cursors.py", line 322, in _query
    conn.query(q)
  File "env/lib/python3.10/site-packages/pymysql/connections.py", line 558, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "env/lib/python3.10/site-packages/pymysql/connections.py", line 822, in _read_query_result
    result.read()
  File "env/lib/python3.10/site-packages/pymysql/connections.py", line 1200, in read
    first_packet = self.connection._read_packet()
  File "env/lib/python3.10/site-packages/pymysql/connections.py", line 772, in _read_packet
    packet.raise_for_error()
  File "env/lib/python3.10/site-packages/pymysql/protocol.py", line 221, in raise_for_error
    err.raise_mysql_exception(self._data)
  File "env/lib/python3.10/site-packages/pymysql/err.py", line 143, in raise_mysql_exception
    raise errorclass(errno, errval)
pymysql.err.OperationalError: (1054, "Unknown column 'a' in 'where clause'")

Fix:
get_link_fields needs to reference the docfield not the doctype for checking whether the field is virtual

@kareemk kareemk requested review from a team and akhilnarang and removed request for a team April 17, 2024 23:56
@github-actions github-actions bot added the add-test-cases Add test case to validate fix or enhancement label Apr 17, 2024
@kareemk
Copy link
Contributor Author

kareemk commented Apr 17, 2024

I'm new to contributing and have found it very hard to run frappe framework tests locally, if you can direct me on how to do that I should be able to add test cases

frappe/model/rename_doc.py Outdated Show resolved Hide resolved
frappe/model/rename_doc.py Outdated Show resolved Hide resolved
@ankush ankush added backport version-14-hotfix backport to version 14 backport version-15-hotfix Backport the PR to v15 and removed add-test-cases Add test case to validate fix or enhancement labels Apr 22, 2024
@ankush ankush enabled auto-merge (squash) April 22, 2024 11:28
frappe/model/rename_doc.py Outdated Show resolved Hide resolved
@ankush ankush merged commit 27948bc into frappe:develop Apr 23, 2024
22 of 23 checks passed
mergify bot pushed a commit that referenced this pull request Apr 23, 2024
mergify bot pushed a commit that referenced this pull request Apr 23, 2024
ankush pushed a commit that referenced this pull request Apr 23, 2024
…26025) (#26119)

(cherry picked from commit 27948bc)

Co-authored-by: Kareem Kouddous <kkouddous@gmail.com>
ankush pushed a commit that referenced this pull request Apr 23, 2024
…26025) (#26118)

(cherry picked from commit 27948bc)

Co-authored-by: Kareem Kouddous <kkouddous@gmail.com>
@kareemk kareemk deleted the fix-renaming-virtual-docfield branch April 23, 2024 19:16
frappe-pr-bot pushed a commit that referenced this pull request Apr 30, 2024
# [14.73.0](v14.72.0...v14.73.0) (2024-04-30)

### Bug Fixes

* 🐛 don't create __init__.py files when gathering pages ([#26045](#26045)) ([#26090](#26090)) ([84fbc40](84fbc40)), closes [#25167](#25167)
* add missing impl for is_column_missing (backport [#26225](#26225)) ([#26226](#26226)) ([b5abe55](b5abe55))
* allow setting dynamic filters for number cards even without developer mode ([7d5b443](7d5b443))
* avoid perm error on dashboard chart ([#26150](#26150)) ([#26156](#26156)) ([6231e1d](6231e1d))
* calendar in Arabic (backport [#26213](#26213)) ([#26215](#26215)) ([67530e3](67530e3)), closes [#26207](#26207)
* compute modal title server side ([#26191](#26191)) ([760ff72](760ff72))
* Dirty form when grid rows are moved ([#26230](#26230)) ([#26233](#26233)) ([ce4fa2a](ce4fa2a))
* filter select perm in get_doctypes_with_read (backport [#26037](#26037)) ([#26039](#26039)) ([e889691](e889691))
* frappe.template.compile(...) is not a function ([#26125](#26125)) ([#26126](#26126)) ([ea5d7b7](ea5d7b7))
* german translations ([#26219](#26219)) ([a40dfdd](a40dfdd))
* **grid_row:** check child table dependent properties whenever a row is selected ([caabb79](caabb79))
* **grid:** ensure that `doc` itself is not null ([a2b61eb](a2b61eb)), closes [#25800](#25800)
* handle case where mimetype is None ([#26131](#26131)) ([#26132](#26132)) ([cc3b654](cc3b654))
* handle null in CSV preview ([#26154](#26154)) ([2e2649b](2e2649b))
* register faulthandler on true stderr only (backport [#26028](#26028)) ([#26033](#26033)) ([45630fe](45630fe))
* rename fields for html, col, section, etc. ([#26188](#26188)) ([1a2411c](1a2411c))
* Renaming when doctype is used as a virtual link docfield fails ([#26025](#26025)) ([#26118](#26118)) ([eea6509](eea6509))
* **report builder:** responsive footer ([#26222](#26222)) ([#26223](#26223)) ([4f0bcf1](4f0bcf1))
* **report_utils:** ensure that delimiter and separator can't be empty ([5301516](5301516))
* **report_view:** allow exporting all rows even if count is disabled ([c0cf52f](c0cf52f))
* retry count per doc instead of global ([#26159](#26159)) ([#26160](#26160)) ([0d6ff95](0d6ff95))
* strip redirect URIs for trailing whitespaces ([#26006](#26006)) ([#26007](#26007)) ([aefc6f9](aefc6f9))
* unknown charset windows-874 problem on incoming mail ([86eff33](86eff33))
* **UX:** warning when printing unsaved documents ([#26229](#26229)) ([#26231](#26231)) ([1530618](1530618))
* web form filtering ([#26122](#26122)) ([#26123](#26123)) ([519fec5](519fec5))

### Features

* enable dynamic filters for standard number cards ([3a4eeb9](3a4eeb9))
* **grid:** Add shift-click for selecting multiple rows ([c9d227a](c9d227a))
* **grid:** Extend clickable area of checkboxes ([2664cf3](2664cf3))
* let users unlock stuck documents (backport [#24782](#24782)) ([#25225](#25225)) ([e58ea03](e58ea03))
* limit oauth client to roles (backport [#26193](#26193)) ([#26195](#26195)) ([5b7bccf](5b7bccf))
frappe-pr-bot pushed a commit that referenced this pull request Apr 30, 2024
# [15.25.0](v15.24.1...v15.25.0) (2024-04-30)

### Bug Fixes

* add missing impl for is_column_missing ([#26225](#26225)) ([#26227](#26227)) ([9490869](9490869))
* **ar:** render fullcalendar in english ([#26207](#26207)) ([#26210](#26210)) ([2f171cd](2f171cd))
* avoid perm error on dashboard chart ([#26150](#26150)) ([#26153](#26153)) ([0909589](0909589))
* **backup:** delete failed backup even if something fails during the backup process ([7c8c41c](7c8c41c))
* calendar in Arabic (backport [#26213](#26213)) ([#26216](#26216)) ([df6291b](df6291b)), closes [#26207](#26207)
* clean up print ([#26170](#26170)) ([#26176](#26176)) ([a41e496](a41e496))
* Dirty form when grid rows are moved ([#26230](#26230)) ([#26234](#26234)) ([c60f25d](c60f25d))
* frappe.template.compile(...) is not a function ([#26125](#26125)) ([#26127](#26127)) ([69e503c](69e503c))
* handle case where mimetype is None ([#26131](#26131)) ([#26133](#26133)) ([0c518a2](0c518a2))
* handle null in CSV preview ([551503a](551503a))
* hide tab button on child table ([#26148](#26148)) ([#26149](#26149)) ([fd42cbf](fd42cbf))
* multistep webform page navigation ([9415f4f](9415f4f))
* perm query for dashboard ([#26239](#26239)) ([#26243](#26243)) ([9ffb8af](9ffb8af))
* Renaming when doctype is used as a virtual link docfield fails ([#26025](#26025)) ([#26119](#26119)) ([724f944](724f944))
* **report builder:** responsive footer ([#26222](#26222)) ([#26224](#26224)) ([f19bff7](f19bff7))
* **report_utils:** ensure that delimiter and separator can't be empty ([#26202](#26202)) ([a1f008c](a1f008c))
* restoring site breaks when checking backup version ([#26186](#26186)) ([f2f167d](f2f167d))
* retry count per doc instead of global ([#26159](#26159)) ([#26161](#26161)) ([256578a](256578a))
* use document language for workflow action ([#26138](#26138)) ([#26139](#26139)) ([876d230](876d230))
* **UX:** warning when printing unsaved documents ([#26229](#26229)) ([#26232](#26232)) ([8826690](8826690))
* web form filtering ([#26122](#26122)) ([0c38f94](0c38f94))

### Features

* Allow usage of `print()` within `safe_exec()` ([#23084](#23084)) ([3ce15f3](3ce15f3))
* Allow user to optimize tables ([#26109](#26109)) ([#26121](#26121)) ([ca7148e](ca7148e))
* Document.remove_tag ([#22970](#22970)) ([#26178](#26178)) ([17ca7f4](17ca7f4))
* limit oauth client to roles (backport [#26193](#26193)) ([#26196](#26196)) ([c8387f8](c8387f8))

### Performance Improvements

* use base32 space for random names instead of base16 (backport [#25497](#25497)) ([#25546](#25546)) ([0723853](0723853))
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 8, 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.

None yet

2 participants