浏览代码

chore: Raise NotImplementedError in base Database class

Methods that have to be overridden should throw NoteImplementedError.
Helps during development :')
version-14
Gavin D'souza 3 年前
父节点
当前提交
713eaf6ac9
共有 2 个文件被更改,包括 8 次插入15 次删除
  1. +4
    -4
      frappe/database/database.py
  2. +4
    -11
      frappe/utils/password.py

+ 4
- 4
frappe/database/database.py 查看文件

@@ -919,13 +919,13 @@ class Database(object):
WHERE table_name = 'tab{0}' AND column_name = '{1}' '''.format(doctype, column))[0][0] WHERE table_name = 'tab{0}' AND column_name = '{1}' '''.format(doctype, column))[0][0]


def has_index(self, table_name, index_name): def has_index(self, table_name, index_name):
pass
raise NotImplementedError


def add_index(self, doctype, fields, index_name=None): def add_index(self, doctype, fields, index_name=None):
pass
raise NotImplementedError


def add_unique(self, doctype, fields, constraint_name=None): def add_unique(self, doctype, fields, constraint_name=None):
pass
raise NotImplementedError


@staticmethod @staticmethod
def get_index_name(fields): def get_index_name(fields):
@@ -951,7 +951,7 @@ class Database(object):
def escape(s, percent=True): def escape(s, percent=True):
"""Excape quotes and percent in given string.""" """Excape quotes and percent in given string."""
# implemented in specific class # implemented in specific class
pass
raise NotImplementedError


@staticmethod @staticmethod
def is_column_missing(e): def is_column_missing(e):


+ 4
- 11
frappe/utils/password.py 查看文件

@@ -10,6 +10,7 @@ from cryptography.fernet import Fernet, InvalidToken
from passlib.hash import pbkdf2_sha256, mysql41 from passlib.hash import pbkdf2_sha256, mysql41
from passlib.registry import register_crypt_handler from passlib.registry import register_crypt_handler
from passlib.context import CryptContext from passlib.context import CryptContext
from pypika.terms import Values


Auth = Table("__Auth") Auth = Table("__Auth")


@@ -51,8 +52,7 @@ def get_decrypted_password(doctype, name, fieldname="password", raise_exception=
& (Auth.encrypted == 1) & (Auth.encrypted == 1)
) )
.limit(1) .limit(1)
.run()
)
).run()


if result and result[0][0]: if result and result[0][0]:
return decrypt(result[0][0]) return decrypt(result[0][0])
@@ -70,17 +70,10 @@ def set_encrypted_password(doctype, name, pwd, fieldname="password"):


# TODO: Simplify this via aliasing methods in `frappe.qb` # TODO: Simplify this via aliasing methods in `frappe.qb`
if frappe.db.db_type == "mariadb": if frappe.db.db_type == "mariadb":
query = (
query.on_duplicate_key_update(Auth.doctype, doctype)
.on_duplicate_key_update(Auth.name, name)
.on_duplicate_key_update(Auth.fieldname, fieldname)
)
query = query.on_duplicate_key_update(Auth.password, Values(Auth.password))
elif frappe.db.db_type == "postgres": elif frappe.db.db_type == "postgres":
query = ( query = (
query.on_conflict(Auth.doctype, Auth.name, Auth.fieldname)
.do_update(Auth.doctype, doctype)
.do_update(Auth.name, name)
.do_update(Auth.fieldname, fieldname)
query.on_conflict(Auth.doctype, Auth.name, Auth.fieldname).do_update(Auth.password)
) )


try: try:


正在加载...
取消
保存