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: multi plugin id was read from the wrong place #240

Merged
merged 1 commit into from
Mar 13, 2025

Conversation

henryiii
Copy link
Collaborator

Found when working on henryiii/validate-pyproject-schema-store#117. Looks like a unit testing bug. There might be an issue with getting the ordering wrong too (it's reporting all the tools are coming from the old location, which won't allow extra schemas to load). Looking into that, might be related though.

Verified

This commit was signed with the committer’s verified signature.
SgtCoDFish Ashley Davis
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
@henryiii
Copy link
Collaborator Author

I'm not sure this was all that important, it just causes the verbose printout to be less helpful. I'm not sure the verbose printout is all that helpful with this, though:

So maybe we can store the plugin name it came from too and use that.

Haven't worked out why the ordering is wrong yet, though. It seems like we have a test for it.

@@ -82,7 +82,7 @@ def __init__(self, tool: str, schema: Schema):

@property
def id(self) -> str:
return self.schema.get("id", "MISSING ID")
return self.schema.get("$id", "MISSING ID")
Copy link
Owner

@abravalheri abravalheri Mar 13, 2025

Choose a reason for hiding this comment

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

So maybe we can store the plugin name it came from too and use that.

You mean for the sotred_plugin.id?

If that is the idea, maybe something like this?

class StoredPlugin:
    def __init__(self, tool: str, schema: Schema, fallback_id: str): ...

    @property
    def id(self) -> str:
        return self.schema.get("$id", self._fallback_id)

...

def load_from_multi_entry_point(...):
    ...
    base_id = entry_point.name
    for tool, schema in output["tools"].items():
        yield StoredPlugin(tool, schema, f"{base_id}:{tool}")
    for i, schema in enumerate(output.get("schemas", [])):
        yield StoredPlugin("", schema, f"{base_id}:{i}")

Or use base_id = f"{fn.__module__}.{fn.__name__}"

(Untested code)

Is that more or less what you had in mind in this suggestion?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, that's roughly what I was thinking. I think we use name or id in a few places, need to make sure none of those assume id is unique. If id is $id, then it is unique. Looks like your first suggestion would handle that, though. 👍

I was able to reproduce the sorting bug.

Copy link
Owner

Choose a reason for hiding this comment

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

I suppose that if the schema is not a tool, it is also reasonable to require $id to be present? (Otherwise how is the schema referenced?).

@abravalheri abravalheri merged commit 60b8ee4 into abravalheri:main Mar 13, 2025
21 checks passed
@abravalheri
Copy link
Owner

Thank you very much.

Haven't worked out why the ordering is wrong yet, though. It seems like we have a test for it.

I suppose we can handle it separately.

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.

None yet

2 participants