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

Frappe Version 14 - TypeError: object of type 'Cursor' has no len() #343

Closed
vineyrawat opened this issue Nov 6, 2024 · 3 comments
Closed

Comments

@vineyrawat
Copy link

Insights ibis framework is not executing queries in frappe v14.23.0 throwing an error of cursor has no len()
but in the case of the latest frappe v14, it is working,

Could anyone please help me, I've been stuck in that issue for around last week

Frappe Version: v14.23.0
Insights Version: v3.0.0
Ibis Framework Version: 9.5.0

In [18]: doc = frappe.get_doc("Insights Data Source v3", "site_db_21")

In [19]: doc.update_table_links()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
File <ipython-input-19-10e889fb690a>:1, in <cell line: 1>()
----> 1 doc.update_table_links()

File ~/stable-bench/apps/insights/insights/insights/doctype/insights_data_source_v3/insights_data_source_v3.py:252, in InsightsDataSourcev3.update_table_links(self, force)
    250 links = []
    251 if self.is_site_db or self.is_frappe_db:
--> 252     links = get_frappedb_table_links(self)
    254 if force:
    255     frappe.db.delete(
    256         "Insights Table Link v3",
    257         {"data_source": [self.name](http://self.name/)},
    258     )

File ~/stable-bench/apps/insights/insights/insights/doctype/insights_data_source_v3/connectors/frappe_db.py:62, in get_frappedb_table_links(data_source)
     51 docfield = db.table("tabDocField")
     52 custom_field = db.table("tabCustom Field")
     54 standard_links = (
     55     docfield.select(
     56         _.fieldname,
     57         _.fieldtype,
     58         _.options,
     59         _.parent,
     60     )
     61     .filter((_.fieldtype == "Link") | (_.fieldtype == "Table"))
---> 62     .execute()
     63 )
     65 custom_links = (
     66     custom_field.select(
     67         _.fieldname,
   (...)
     73     .execute()
     74 )
     76 standard_links = standard_links.to_dict(orient="records")

File ~/insights-bench/env/lib/python3.10/site-packages/ibis/expr/types/core.py:396, in Expr.execute(self, limit, params, **kwargs)
    378 def execute(
    379     self,
    380     limit: int | str | None = "default",
    381     params: Mapping[ir.Value, Any] | None = None,
    382     **kwargs: Any,
    383 ):
    384     """Execute an expression against its backend if one exists.
    385
    386     Parameters
   (...)
    394         Keyword arguments
    395     """
--> 396     return self._find_backend(use_default=True).execute(
    397         self, limit=limit, params=params, **kwargs
    398     )

File ~/insights-bench/env/lib/python3.10/site-packages/ibis/backends/mysql/__init__.py:376, in Backend.execute(self, expr, limit, **kwargs)
    373 schema = table.schema()
    375 with self._safe_raw_sql(sql) as cur:
--> 376     result = self._fetch_from_cursor(cur, schema)
    377 return expr.__pandas_result__(result)

File ~/insights-bench/env/lib/python3.10/site-packages/ibis/backends/mysql/__init__.py:548, in Backend._fetch_from_cursor(self, cursor, schema)
    545 from ibis.backends.mysql.converter import MySQLPandasData
    547 try:
--> 548     df = pd.DataFrame.from_records(
    549         cursor, columns=schema.names, coerce_float=True
    550     )
    551 except Exception:
    552     # clean up the cursor if we fail to create the DataFrame
    553     #
    554     # in the sqlite case failing to close the cursor results in
    555     # artificially locked tables
    556     cursor.close()

File ~/insights-bench/env/lib/python3.10/site-packages/pandas/core/frame.py:2491, in DataFrame.from_records(cls, data, index, exclude, columns, coerce_float, nrows)
   2489     arr_columns = columns
   2490 else:
-> 2491     arrays, arr_columns = to_arrays(data, columns)
   2492     if coerce_float:
   2493         for i, arr in enumerate(arrays):

File ~/insights-bench/env/lib/python3.10/site-packages/pandas/core/internals/construction.py:811, in to_arrays(data, columns, dtype)
    793 def to_arrays(
    794     data, columns: Index | None, dtype: DtypeObj | None = None
    795 ) -> tuple[list[ArrayLike], Index]:
    796     """
    797     Return list of arrays, columns.
    798
   (...)
    808     Ensures that len(result_arrays) == len(result_index).
    809     """
--> 811     if not len(data):
    812         if isinstance(data, np.ndarray):
    813             if data.dtype.names is not None:
    814                 # i.e. numpy structured array

TypeError: object of type 'Cursor' has no len()
@nextchamp-saqib
Copy link
Member

Does it work with v14.85.0?

This is probably related to the pandas version. Can you share your pandas version?

@vineyrawat
Copy link
Author

Pandas version is 2.2.3

@nextchamp-saqib
Copy link
Member

I am not sure what is wrong. If it works with the latest v14 then it's not worth investigating. Please update to the latest v14 version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants