Skip to content

Commit

Permalink
fix: cannot upload csv files
Browse files Browse the repository at this point in the history
  • Loading branch information
nextchamp-saqib committed Nov 16, 2024
1 parent df84790 commit 8b44475
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 9 additions & 3 deletions insights/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
from frappe.rate_limiter import rate_limit

from insights.decorators import insights_whitelist, validate_type
from insights.insights.doctype.insights_data_source_v3.connectors.duckdb import (
get_duckdb_connection,
)
from insights.insights.doctype.insights_data_source_v3.ibis_utils import (
get_columns_from_schema,
)
Expand Down Expand Up @@ -149,9 +152,12 @@ def import_csv_data(filename: str):
uploads.save(ignore_permissions=True)

ds = frappe.get_doc("Insights Data Source v3", "uploads")
db = ds._get_ibis_backend()
db = get_duckdb_connection(ds, read_only=False)

table = db.read_csv(file_path, table_name=table_name)
db.create_table(table_name, table, overwrite=True)
try:
table = db.read_csv(file_path, table_name=table_name)
db.create_table(table_name, table, overwrite=True)
finally:
db.disconnect()

InsightsTablev3.bulk_create(ds.name, [table_name])
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from frappe.utils import get_files_path


def get_duckdb_connection(data_source):
def get_duckdb_connection(data_source, read_only=True):
path = os.path.realpath(get_files_path(is_private=1))
path = os.path.join(path, f"{data_source.database_name}.duckdb")
return ibis.duckdb.connect(path, read_only=True)
return ibis.duckdb.connect(path, read_only=read_only)

0 comments on commit 8b44475

Please sign in to comment.