Draft: add rdmo.config app for Plugin model (plugin management)#1436
Draft: add rdmo.config app for Plugin model (plugin management)#1436MyPyDavid wants to merge 127 commits into2.5.0/releasefrom
rdmo.config app for Plugin model (plugin management)#1436Conversation
jochenklar
left a comment
There was a problem hiding this comment.
Great! Lets discuss in the meeting.
rdmo/config/models.py
Outdated
| help_text=_('Designates whether this plugin is generally available for projects.') | ||
| ) | ||
|
|
||
| class PluginType(models.TextChoices): |
There was a problem hiding this comment.
I think we can do without this, the Plugin(-class) should know this.
There was a problem hiding this comment.
I have now something like this as a utils.py function, to detect the plugin type from the class inheritance.
PLUGIN_BASES = {
'optionset_provider': OptionsetProvider,
'export': Export,
'import': Import,
'issue_provider': IssueProvider,
}
def detect_plugin_type(plugin_class):
if not issubclass(plugin_class, Plugin):
return "not_an_rdmo_plugin"
for type_name, base_cls in PLUGIN_BASES.items():
if issubclass(plugin_class, base_cls):
return type_name
return 'rdmo_plugin_unknown_type'I kept it as a property in the Plugin model:
@property
def plugin_type(self) -> str:
try:
plugin_class = self.get_class()
except Exception as e:
return e.__class__.__qualname__.lower()
return detect_plugin_type(plugin_class)rdmo.config app for Plugin model
|
I'm getting some strange DB errors for mysql in ci(and sqlite in local testing). django.db.utils.OperationalError: foreign key mismatch - "questions_question" referencing "domain_attribute"From the ci logs: # at
query = b'ALTER TABLE `domain_attribute` DROP COLUMN `attributeentity_ptr_id`' django.db.utils.OperationalError:
(1829, "Cannot drop column 'attributeentity_ptr_id':
needed in a foreign key constraint 'questions_questionse_attribute_id_30ee3ea9_fk_domain_at' of table 'questions_questionset'")The problem can be resolved by removing the app |
Think that I found the bug with help of GPT and could fix it by adding a single dependency to the GPT:
|
rdmo.config app for Plugin modelrdmo.config app for Plugin model
|
Ok got it! Good explanation by ChatGPT. This is why you don't do multi-table inheritance and why past-Jochen dismantled it. |
107f379 to
f5eae22
Compare
|
7031a4b to
6875f9a
Compare
6875f9a to
9791229
Compare
dceca19 to
ae887db
Compare
| return self.filter(Q(groups=None) | Q(groups__in=groups)) | ||
|
|
||
|
|
||
| class ForSiteQuerySetMixin: |
There was a problem hiding this comment.
Could implement this already in #1488, see #1488 (comment)
27516be to
4026f9a
Compare
rdmo.config app for Plugin modelrdmo.config app for Plugin model (plugin managament)
Signed-off-by: David Wallace <david.wallace@tu-darmstadt.de>
Signed-off-by: David Wallace <david.wallace@tu-darmstadt.de>
Signed-off-by: David Wallace <david.wallace@tu-darmstadt.de>
Signed-off-by: David Wallace <david.wallace@tu-darmstadt.de>
Signed-off-by: David Wallace <david.wallace@tu-darmstadt.de>
Signed-off-by: David Wallace <david.wallace@tu-darmstadt.de>
Signed-off-by: David Wallace <david.wallace@tu-darmstadt.de>
| def __str__(self): | ||
| return self.uri | ||
|
|
||
| def save(self, *args, **kwargs): |
There was a problem hiding this comment.
Maybe create instance of plugin here an read plugin_type from the class. Handle raw.
There was a problem hiding this comment.
are you sure that the raw case needs to be handled? I could not find any other model that does it on the save method, only the signal handlers are using it so far..
Otherwise it could be simply
if raw:
return super().save(*args, **kwargs)right?
There was a problem hiding this comment.
Yes you are right, no raw needed. Fixtures use a bulk insert.
Signed-off-by: David Wallace <david.wallace@tu-darmstadt.de>
Signed-off-by: David Wallace <david.wallace@tu-darmstadt.de>
Signed-off-by: David Wallace <david.wallace@tu-darmstadt.de>
Signed-off-by: David Wallace <david.wallace@tu-darmstadt.de>
Signed-off-by: David Wallace <david.wallace@tu-darmstadt.de>
Signed-off-by: David Wallace <david.wallace@tu-darmstadt.de>
Signed-off-by: David Wallace <david.wallace@tu-darmstadt.de>
Signed-off-by: David Wallace <david.wallace@tu-darmstadt.de>
rdmo.config app for Plugin model (plugin managament)rdmo.config app for Plugin model (plugin management)
Signed-off-by: David Wallace <david.wallace@tu-darmstadt.de>
Signed-off-by: David Wallace <david.wallace@tu-darmstadt.de>
Signed-off-by: David Wallace <david.wallace@tu-darmstadt.de>
…rsion Signed-off-by: David Wallace <david.wallace@tu-darmstadt.de>
Signed-off-by: David Wallace <david.wallace@tu-darmstadt.de>
jochenklar
left a comment
There was a problem hiding this comment.
Thanks for all the work. I added a lot of comments, and fixed some things already in #1574.
| for plugin in Plugin.objects.filter(plugin_type='optionset_provider').exclude(url_name='') | ||
| } | ||
|
|
||
| if not providers: |
There was a problem hiding this comment.
I think this is always empty, why should Plugin have any rows when running the migration?
| @@ -85,16 +86,27 @@ def get_context_data(self, **kwargs): | |||
| context['ancestors_import'] = ancestors_import | |||
| context['memberships'] = memberships.order_by('user__last_name', '-project__level') | |||
| context['integrations'] = integrations.order_by('provider_key', '-project__level') | |||
There was a problem hiding this comment.
Here we need to do something about existing integrations in the database, which do not have a configured plugin (anymore).
| verbose_name=_('Plugin settings'), | ||
| help_text=_('Contains the settings for this plugin in JSON format.'), | ||
| ) | ||
| plugin_type = models.SlugField( |
There was a problem hiding this comment.
This should be restricted to PLUGIN_TYPES, right? I see that's in the serializer and in admin, but this could be a regular choices arg.
| return self.filter(queryset) | ||
|
|
||
|
|
||
| def for_context(self, project=None, plugin_type=None, plugin_types=None, |
There was a problem hiding this comment.
We should refactor this after the rebase and use filter_tasks_or_views_for_project since it is basically the same.
There was a problem hiding this comment.
The plugin specific part can be a filter afterwards.
There was a problem hiding this comment.
The order needs also be applied, since it matters when two plugins accept the same files for upload.
| return ( | ||
| self | ||
| .filter_for_site(project.site) | ||
| .filter(catalogs=project.catalog) |
There was a problem hiding this comment.
This needs to be .filter(models.Q(catalogs=None) | models.Q(catalogs=project.catalog)).
| python_path = declared.get("python_path") | ||
| restore_plugins = None | ||
| if python_path and python_path not in settings.PLUGINS: | ||
| restore_plugins = list(settings.PLUGINS) |
There was a problem hiding this comment.
PLUGINS is a list, if not it should crash.
| # If no import source and only --clear, we are done after clear phase. | ||
| # If no import source and no clear, error. | ||
| if not plugins_from_settings and not clear: | ||
| raise CommandError("Nothing to do.") |
There was a problem hiding this comment.
This is not an error. I don't know if there is a CommandInfo. Maybe just a self.stdout.write and return?
| raise CommandError("\n".join(e.messages)) from e | ||
|
|
||
| plugins_from_settings.extend( | ||
| merge_legacy_and_current_plugins(legacy_plugins, plugins) |
There was a problem hiding this comment.
Maybe the script should not merge, but first insert the regular plugins and then read and insert the legacy plugins and skipping the ones that are already in the database (by python path).
There was a problem hiding this comment.
This file is still to complex, please remove all unnecessary code and comments. Remove all typing. The management class should be at the top of file for readability. All methods (if they are needed) should be in Command.
Also I don't get the part about the database transactions.
There was a problem hiding this comment.
Maybe the script should be split in two, one for the legacy settings, and one for the future regular RDMO setup. I guess that would make things easier.
|
thanks! The #1574 also looks good, I'll try to go through the comments ASAP :D |
Description
rdmo.configappPluginmodelPluginbehaves similar to any other element (Catalog, Taks, View)PLUGINS = [ .. ]which replaces the legacy settings (e.g.PROJECT_IMPORT).Deprecations and legacy
rdmo.core.pluginsrdmo.config.pluginsand renamed toPluginBaseRelated issue: #1413