fix: Fixes mariadb orm to return list instead of tuple as the typisat… (#27179)
* fix: Fixes mariadb orm to return list instead of tuple as the typisation suggests it * fix: inverted fix for pg: Expect tuple as data_type for _transform_result * fix: Fixed failing upstream spec due to data_type change
This commit is contained in:
parent
333f08dc83
commit
8a2aa92389
3 changed files with 25 additions and 8 deletions
|
|
@ -144,7 +144,7 @@ class Database:
|
|||
def _transform_query(self, query: Query, values: QueryValues) -> tuple:
|
||||
return query, values
|
||||
|
||||
def _transform_result(self, result: list[tuple]) -> list[tuple]:
|
||||
def _transform_result(self, result: list[tuple] | tuple[tuple]) -> tuple[tuple]:
|
||||
return result
|
||||
|
||||
def _clean_up(self):
|
||||
|
|
|
|||
|
|
@ -225,6 +225,9 @@ class PostgresDatabase(PostgresExceptionUtil, Database):
|
|||
)
|
||||
return db_size[0].get("database_size")
|
||||
|
||||
def _transform_result(self, result: list[tuple] | tuple[tuple]) -> tuple[tuple]:
|
||||
return tuple(result) if isinstance(result, list) else result
|
||||
|
||||
# pylint: disable=W0221
|
||||
def sql(self, query, values=EmptyQueryValues, *args, **kwargs):
|
||||
return super().sql(modify_query(query), modify_values(values), *args, **kwargs)
|
||||
|
|
|
|||
|
|
@ -572,6 +572,20 @@ class TestDB(FrappeTestCase):
|
|||
|
||||
frappe.db.rollback()
|
||||
|
||||
def test_get_list_return_value_data_type(self):
|
||||
frappe.db.delete("Note")
|
||||
|
||||
frappe.get_doc(doctype="Note", title="note1", content="something").insert()
|
||||
frappe.get_doc(doctype="Note", title="note2", content="someting else").insert()
|
||||
|
||||
note_docs = frappe.db.sql("select * from `tabNote`")
|
||||
|
||||
# should return both records
|
||||
self.assertEqual(len(note_docs), 2)
|
||||
|
||||
# data-type should be list
|
||||
self.assertIsInstance(note_docs, tuple)
|
||||
|
||||
@run_only_if(db_type_is.POSTGRES)
|
||||
def test_modify_query(self):
|
||||
from frappe.database.postgres.database import modify_query
|
||||
|
|
@ -1111,9 +1125,9 @@ class TestPostgresSchemaQueryIndependence(ExtFrappeTestCase):
|
|||
|
||||
if frappe.db.sql(
|
||||
"""SELECT 1
|
||||
FROM information_schema.schemata
|
||||
WHERE schema_name = 'alt_schema'
|
||||
limit 1 """
|
||||
FROM information_schema.schemata
|
||||
WHERE schema_name = 'alt_schema'
|
||||
LIMIT 1 """
|
||||
):
|
||||
self.cleanup()
|
||||
|
||||
|
|
@ -1244,19 +1258,19 @@ class TestPostgresSchemaQueryIndependence(ExtFrappeTestCase):
|
|||
rows = frappe.db.sql(f'select * from "tab{self.test_table_name}"')
|
||||
self.assertEqual(
|
||||
rows,
|
||||
[
|
||||
(
|
||||
(
|
||||
"a",
|
||||
"b",
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
) # there should be a single row in the public table
|
||||
|
||||
# when schema is changed to alt_schema, the alt_schema tables should be addressed by search path
|
||||
frappe.conf["db_schema"] = "alt_schema"
|
||||
frappe.db.connect()
|
||||
rows = frappe.db.sql(f'select * from "tab{self.test_table_name}"')
|
||||
self.assertEqual(rows, []) # there are no records in the alt_schema table
|
||||
self.assertEqual(rows, ()) # there are no records in the alt_schema table
|
||||
|
||||
del frappe.conf["db_schema"]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue