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: make plugin_version optional when adding plugin data #13

Merged
merged 2 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 9 additions & 4 deletions src/nendo/library/sqlalchemy_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -917,10 +917,10 @@ def update_track(
def add_plugin_data(
self,
track_id: Union[str, uuid.UUID],
plugin_name: str,
plugin_version: str,
key: str,
value: Any,
plugin_name: str,
plugin_version: Optional[str] = None,
user_id: Optional[Union[str, uuid.UUID]] = None,
replace: bool = False,
) -> schema.NendoPluginData:
Expand All @@ -929,10 +929,12 @@ def add_plugin_data(
Args:
track_id (Union[str, UUID]): ID of the track to which
the plugin data should be added.
plugin_name (str): Name of the plugin.
plugin_version (str): Version of the plugin.
key (str): Key under which to save the data.
value (Any): Data to save.
plugin_name (str): Name of the plugin.
plugin_version (str, optional): Version of the plugin. If not specified,
the currently loaded version of the plugin given by `plugin_name`
will be used.
user_id (Union[str, UUID], optional): ID of user adding the plugin data.
replace (bool, optional): Flag that determines whether
the last existing data point for the given plugin name and -version
Expand All @@ -944,6 +946,9 @@ def add_plugin_data(
# create plugin data
user_id = self._ensure_user_uuid(user_id)
value_converted = self._convert_plugin_data(value=value, user_id=user_id)
if plugin_version is None:
plugin = getattr(self.nendo_instance.plugins, plugin_name)
plugin_version = plugin.version
plugin_data = schema.NendoPluginDataCreate(
track_id=ensure_uuid(track_id),
user_id=ensure_uuid(user_id),
Expand Down
10 changes: 6 additions & 4 deletions src/nendo/schema/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,20 +515,22 @@ def remove_meta(self, key: str) -> NendoTrack:

def add_plugin_data(
self,
plugin_name: str,
plugin_version: str,
key: str,
value: str,
plugin_name: str,
plugin_version: Optional[str] = None,
user_id: Optional[Union[str, uuid.UUID]] = None,
replace: bool = True,
) -> NendoTrack:
"""Add plugin data to a NendoTrack and persist changes into the DB.

Args:
plugin_name (str): Name of the plugin.
plugin_version (str): Version of the plugin.
key (str): Key under which to save the data.
value (Any): Data to save.
plugin_name (str): Name of the plugin.
plugin_version (str): Version of the plugin. If none is given,
the currently loaded version of the plugin given by `plugin_name`
will be used.
user_id (Union[str, UUID], optional): ID of user adding the plugin data.
replace (bool, optional): Flag that determines whether
the last existing data point for the given plugin name and -version
Expand Down