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 showing !source on tags when tags cog is reloaded #3005

Merged
merged 2 commits into from
May 21, 2024

Conversation

hedyhli
Copy link
Member

@hedyhli hedyhli commented Apr 6, 2024

Closes #2022

image
image

TLDR

Invoking !source <tag> should now work even after the tags cog is reloaded.

Long description

Previously the source command checks for the source object's class after getting it from the SourceType converter. When the tags cog is reloaded, TagIdentifier is redefined. We were checking whether the old TagIdentifier class (the type() of an instance of the old TagIdentifier) equals the newly defined TagIdentifier class. This returns false because the TagIdentifier class is redefined when the tags cog is reloaded, which caused tags, correctly identified by Source converter, to be unable to be identified in the source cog.

The fix takes advantage of the fact that the source converter could correctly identify tags objects even after the tags cog reloads, and use enum comparisons rather than isinstance/type() to obtain the source type of whatever the source converter returns.

Since we're no longer using the source converter as an actual converter, the function is moved to the source cog instead, and it still works fine.

@hedyhli hedyhli added t: bug Something isn't working a: backend Related to internal functionality and utilities (error_handler, logging, security, utils and core) p: 2 - normal Normal Priority s: needs review Author is waiting for someone to review and approve labels Apr 6, 2024
bot/exts/info/source.py Outdated Show resolved Hide resolved
Previously the source command checks for the source object's class after
getting it from the SourceType converter. When the tags cog is reloaded,
TagIdentifier is redefined. We were checking whether the old
TagIdentifier class (the `type()` of an instance of the old
TagIdentifier) equals the newly defined TagIdentifier class. This
returns false because the TagIdentifier class is redefined when the tags
cog is reloaded, which caused tags, correctly identified by Source
converter, to be unable to be identified in the source cog.

The fix takes advantage of the fact that the source converter could
correctly identify tags objects even after the tags cog reloads, and use
enum comparisons rather than `isinstance`/`type()` to obtain the source
type of whatever the source converter returns.

Since we're no longer using the source converter as an actual converter,
the function is moved to the source cog instead, and it still works
fine.
@hedyhli hedyhli force-pushed the fix/source-command-for-tags branch from da1c12e to ff1d3a8 Compare April 8, 2024 00:46
@hedyhli hedyhli requested a review from wookie184 April 8, 2024 00:46
Copy link
Contributor

@wookie184 wookie184 left a comment

Choose a reason for hiding this comment

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

Looks great, thanks!

Copy link
Member

@vivekashok1221 vivekashok1221 left a comment

Choose a reason for hiding this comment

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

LGTM 🌟

@hedyhli hedyhli merged commit a122285 into main May 21, 2024
5 checks passed
@hedyhli hedyhli deleted the fix/source-command-for-tags branch May 21, 2024 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: backend Related to internal functionality and utilities (error_handler, logging, security, utils and core) p: 2 - normal Normal Priority s: needs review Author is waiting for someone to review and approve t: bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect handling of tags by the !source command
3 participants