-
Notifications
You must be signed in to change notification settings - Fork 2k
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
feat: Add ByteStream
resolved_mime_type
property
#7670
Conversation
Pull Request Test Coverage Report for Build 9003061415Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
ByteStream
resolved_mime_type
property
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why we made this PR bigger than needed? I wouldn't rely on objects' meta, let's just fix the expected behaviour
@@ -86,7 +86,7 @@ def run(self, sources: List[Union[str, Path, ByteStream]]) -> Dict[str, List[Uni | |||
if isinstance(source, Path): | |||
mime_type = self._get_mime_type(source) | |||
elif isinstance(source, ByteStream): | |||
mime_type = source.meta.get("content_type", None) | |||
mime_type = source.resolved_mime_type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the only change should be
mime_type = source.resolved_mime_type | |
mime_type = source.mime_type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @masci @wochinge and I went back and forth on this one in the background for several rounds before deciding on this approach.
We can't employ this simple solution without breaking some existing components i.e. ContentFetcher that uses metadata of the bytestream to set content_type. We have diversion between local files that set mime_type directly and web based fetches that set content type. And now this property resolves the mime_type regardless of where the data comes from. That's the idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not really breaking, it's more that those components are bugged no? I think by supporting the buggy behaviour we pile up tech debt and make the code more complex, is it really worth it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, i can do that as well. We can find all the references of content_type and replace it, in one PR. Wdyt @wochinge ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this will work, we have to change a few things in various tests, in link content fetcher but the change won't have widespread impact on users. Thanks @masci
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree that just relying on .mime_type
seems simpler - hard for me to overlook the requirements of these other components though so I don't think i'm a good judge here
Dropping in favour of #7681 |
Why:
Enhance the MIME type resolution process for the
ByteStream
data class. It introduces a more flexible and priority-based approach to determine the MIME type of aByteStream
, crucial for handling data from diverse sources with varying MIME type declarations.FileTypeRouter
should get mime type fromByteStream
mime type attribute instead of `meta #7633What:
How can it be used:
ByteStream
instance. This is particularly useful for applications that process both local files and streams of data fetched from the webByteStream
(local, web resource etc etc)How did you test it:
Notes for the reviewer: