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

bugfix/correctly share session handler across ingest docs #1806

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 0.10.29-dev0
## 0.10.29-dev1

### Enhancements

Expand All @@ -8,6 +8,8 @@

### Fixes

* **Ingest session handler not being shared correctly** All ingest docs that leverage the session handler should only need to set it once per process. It was recreating it each time because the right values weren't being set nor available given how dataclasses work in python.

## 0.10.28

### Enhancements
Expand Down Expand Up @@ -1627,4 +1629,4 @@ of an email.

## 0.2.0

* Initial release of unstructured
* Initial release of unstructured
2 changes: 1 addition & 1 deletion unstructured/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.10.29-dev0" # pragma: no cover
__version__ = "0.10.29-dev1" # pragma: no cover
6 changes: 3 additions & 3 deletions unstructured/ingest/connector/google_drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json
import os
import typing as t
from dataclasses import dataclass
from dataclasses import dataclass, field
from datetime import datetime
from mimetypes import guess_extension
from pathlib import Path
Expand Down Expand Up @@ -85,7 +85,7 @@ class SimpleGoogleDriveConfig(ConfigSessionHandleMixin, BaseConnectorConfig):
# Google Drive Specific Options
drive_id: str
service_account_key: str
extension: t.Optional[str]
extension: t.Optional[str] = None
recursive: bool = False

def __post_init__(self):
Expand All @@ -105,7 +105,7 @@ def create_session_handle(
@dataclass
class GoogleDriveIngestDoc(IngestDocSessionHandleMixin, IngestDocCleanupMixin, BaseIngestDoc):
connector_config: SimpleGoogleDriveConfig
meta: t.Dict[str, str]
meta: t.Dict[str, str] = field(default_factory=dict)
registry_name: str = "google_drive"

@property
Expand Down
2 changes: 1 addition & 1 deletion unstructured/ingest/connector/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class JiraIngestDoc(IngestDocSessionHandleMixin, IngestDocCleanupMixin, BaseInge
"""

connector_config: SimpleJiraConfig
file_meta: JiraFileMeta
file_meta: t.Optional[JiraFileMeta] = None
registry_name: str = "jira"

@cached_property
Expand Down
1 change: 1 addition & 0 deletions unstructured/ingest/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ def create_session_handle(self) -> BaseSessionHandle:
session related resources across all document handling for a given subprocess."""


@dataclass
class IngestDocSessionHandleMixin:
connector_config: ConfigSessionHandleMixin
_session_handle: t.Optional[BaseSessionHandle] = None
Expand Down
23 changes: 13 additions & 10 deletions unstructured/ingest/pipeline/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,26 @@ def run(self, ingest_doc_dict: dict) -> t.Optional[str]:
try:
global session_handle
doc = create_ingest_doc_from_dict(ingest_doc_dict)
filename = doc.filename
if not self.read_config.re_download and filename.is_file() and filename.stat().st_size:
logger.info(f"File exists: {filename}, skipping download")
return filename
if isinstance(doc, IngestDocSessionHandleMixin):
if session_handle is None:
# create via doc.session_handle, which is a property that creates a
# session handle if one is not already defined
session_handle = doc.session_handle
else:
doc.session_handle = session_handle
# does the work necessary to load file into filesystem
# in the future, get_file_handle() could also be supported
if self.retry_strategy:
self.retry_strategy(doc.get_file)
doc._session_handle = session_handle
if (
not self.read_config.re_download
and doc.filename.is_file()
and doc.filename.stat().st_size
):
logger.info(f"File exists: {doc.filename}, skipping download")
# Still need to fetch metadata if file exists locally
doc.update_source_metadata()
else:
doc.get_file()
if self.retry_strategy:
self.retry_strategy(doc.get_file)
else:
doc.get_file()
for k, v in doc.to_dict().items():
ingest_doc_dict[k] = v
return doc.filename
Expand Down
Loading