Browse Source

Merge pull request #16454 from resilient-tech/ignore-DoesNotExistError

fix!: ignore `DoesNotExistError` inside `get_cached_value`
version-14
gavin 3 years ago
committed by GitHub
parent
commit
16324e9cd2
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 12 deletions
  1. +6
    -1
      frappe/__init__.py
  2. +14
    -11
      frappe/utils/data.py

+ 6
- 1
frappe/__init__.py View File

@@ -896,7 +896,12 @@ def clear_document_cache(doctype, name):
cache().hdel('document_cache', key)

def get_cached_value(doctype, name, fieldname, as_dict=False):
doc = get_cached_doc(doctype, name)
try:
doc = get_cached_doc(doctype, name)
except DoesNotExistError:
clear_last_message()
return

if isinstance(fieldname, str):
if as_dict:
throw('Cannot make dict for single fieldname')


+ 14
- 11
frappe/utils/data.py View File

@@ -1645,18 +1645,21 @@ def validate_json_string(string: str) -> None:
raise frappe.ValidationError

def get_user_info_for_avatar(user_id: str) -> Dict:
user_info = {
"email": user_id,
"image": "",
"name": user_id
}
try:
user_info["email"] = frappe.get_cached_value("User", user_id, "email")
user_info["name"] = frappe.get_cached_value("User", user_id, "full_name")
user_info["image"] = frappe.get_cached_value("User", user_id, "user_image")
except Exception:
frappe.local.message_log = []
return user_info
user = frappe.get_cached_doc("User", user_id)
return {
"email": user.email,
"image": user.user_image,
"name": user.full_name
}

except frappe.DoesNotExistError:
frappe.clear_last_message()
return {
"email": user_id,
"image": "",
"name": user_id
}


def validate_python_code(string: str, fieldname=None, is_expression: bool = True) -> None:


Loading…
Cancel
Save