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

fix: use guess_format when plugin for format not found #2735

Merged
merged 3 commits into from
Mar 20, 2024

Conversation

edmondchuc
Copy link
Contributor

@edmondchuc edmondchuc commented Mar 16, 2024

Summary of changes

Fixes #2734

  • add fallback to use rdflib.util.guess_format when PluginException occurs
  • ensure PluginException still occurs when guess_format fails

Checklist

  • Checked that there aren't other open pull requests for
    the same change.
  • Checked that all tests and type checking passes.
  • If the change adds new features or changes the RDFLib public API:
    • Created an issue to discuss the change and get in-principle agreement.
    • Considered adding an example in ./examples.
  • If the change has a potential impact on users of this project:
    • Added or updated tests that fail without the change.
    • Updated relevant documentation to avoid inaccuracies.
    • Considered adding additional documentation.
  • Considered granting push permissions to the PR branch,
    so maintainers can fix minor issues and keep your PR up to date.

@coveralls
Copy link

Coverage Status

coverage: 90.971% (+0.01%) from 90.959%
when pulling c7f9b6f on fix/issue-2734
into 9834665 on main.

Comment on lines +1478 to +1489
try:
parser = plugin.get(format, Parser)()
except plugin.PluginException:
# Handle the case when a URLInputSource returns RDF but with the headers
# as a format that does not exist in the plugin system.
# Use guess_format to guess the format based on the input's file suffix.
format = rdflib.util.guess_format(
source if not isinstance(source, InputSource) else str(source)
)
if format is None:
raise
parser = plugin.get(format, Parser)()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may be able to factor this logic out into a function. That way, we can test it with a mock URL object rather than a real web request over the network.

@nicholascar nicholascar merged commit cf427b0 into main Mar 20, 2024
20 checks passed
@nicholascar nicholascar deleted the fix/issue-2734 branch March 20, 2024 02:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Graph.parse: Guess format when remote source content type is "text/plain"
3 participants