refactor: Use db.set_single_value (#35668)

I just applied semgrep autofix. Untested completed, review before merging.

```yaml
- id: frappe-set-value-semantics
  patterns:
    - pattern-either:
      - pattern: frappe.db.set_value($DOCTYPE, None, $...AFTER)
      - pattern: frappe.db.set_value($DOCTYPE, $DOCTYPE, $...AFTER)
  fix: frappe.db.set_single_value($DOCTYPE, $...AFTER)
  message: |
    If $DOCTYPE is a single doctype then using `frappe.db.set_value` is discouraged for setting values in DB. Use db.set_single_value for single doctype instead.
  languages: [python]
  severity: ERROR
```
This commit is contained in:
Ankush Menat
2023-06-13 17:30:38 +05:30
committed by GitHub
parent b43e068852
commit a3ea985348
43 changed files with 124 additions and 142 deletions

View File

@@ -87,13 +87,13 @@ class TestCurrencyExchange(unittest.TestCase):
cache.delete(key)
def tearDown(self):
frappe.db.set_value("Accounts Settings", None, "allow_stale", 1)
frappe.db.set_single_value("Accounts Settings", "allow_stale", 1)
self.clear_cache()
def test_exchange_rate(self, mock_get):
save_new_records(test_records)
frappe.db.set_value("Accounts Settings", None, "allow_stale", 1)
frappe.db.set_single_value("Accounts Settings", "allow_stale", 1)
# Start with allow_stale is True
exchange_rate = get_exchange_rate("USD", "INR", "2016-01-01", "for_buying")
@@ -124,7 +124,7 @@ class TestCurrencyExchange(unittest.TestCase):
settings.save()
# Update exchange
frappe.db.set_value("Accounts Settings", None, "allow_stale", 1)
frappe.db.set_single_value("Accounts Settings", "allow_stale", 1)
# Start with allow_stale is True
exchange_rate = get_exchange_rate("USD", "INR", "2016-01-01", "for_buying")
@@ -152,8 +152,8 @@ class TestCurrencyExchange(unittest.TestCase):
def test_exchange_rate_strict(self, mock_get):
# strict currency settings
frappe.db.set_value("Accounts Settings", None, "allow_stale", 0)
frappe.db.set_value("Accounts Settings", None, "stale_days", 1)
frappe.db.set_single_value("Accounts Settings", "allow_stale", 0)
frappe.db.set_single_value("Accounts Settings", "stale_days", 1)
exchange_rate = get_exchange_rate("USD", "INR", "2016-01-01", "for_buying")
self.assertEqual(exchange_rate, 60.0)
@@ -175,8 +175,8 @@ class TestCurrencyExchange(unittest.TestCase):
exchange_rate = get_exchange_rate("USD", "INR", "2016-01-15", "for_buying")
self.assertEqual(exchange_rate, 65.1)
frappe.db.set_value("Accounts Settings", None, "allow_stale", 0)
frappe.db.set_value("Accounts Settings", None, "stale_days", 1)
frappe.db.set_single_value("Accounts Settings", "allow_stale", 0)
frappe.db.set_single_value("Accounts Settings", "stale_days", 1)
self.clear_cache()
exchange_rate = get_exchange_rate("USD", "INR", "2016-01-30", "for_buying")

View File

@@ -211,7 +211,7 @@ def add_standard_navbar_items():
def add_app_name():
frappe.db.set_value("System Settings", None, "app_name", "ERPNext")
frappe.db.set_single_value("System Settings", "app_name", "ERPNext")
def setup_log_settings():