Project

Profile

Help

Issue #5353

closed

app_label is not set on the models in pulpcore-plugin

Added by ttereshc almost 5 years ago. Updated over 4 years ago.

Status:
CLOSED - CURRENTRELEASE
Priority:
Normal
Assignee:
Category:
-
Sprint/Milestone:
Start date:
Due date:
Estimated time:
Severity:
2. Medium
Version:
Platform Release:
OS:
Triaged:
Yes
Groomed:
Yes
Sprint Candidate:
No
Tags:
Sprint:
Sprint 60
Quarter:

Description

If you create a relation (foreign key, onetoone, manytomany) in a plugin to any model redefined in plugin API (pulpcore.plugin.models), the following error occurs:

 $ django-admin makemigrations
    Traceback (most recent call last):
      File "/usr/local/lib/pulp/bin/django-admin", line 11, in <module>
        sys.exit(execute_from_command_line())
      File "/usr/local/lib/pulp/lib64/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
        utility.execute()
      File "/usr/local/lib/pulp/lib64/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
        self.fetch_command(subcommand).run_from_argv(self.argv)
      File "/usr/local/lib/pulp/lib64/python3.6/site-packages/django/core/management/base.py", line 323, in run_from_argv
        self.execute(*args, **cmd_options)
      File "/usr/local/lib/pulp/lib64/python3.6/site-packages/django/core/management/base.py", line 361, in execute
        self.check()
      File "/usr/local/lib/pulp/lib64/python3.6/site-packages/django/core/management/base.py", line 390, in check
        include_deployment_checks=include_deployment_checks,
      File "/usr/local/lib/pulp/lib64/python3.6/site-packages/django/core/management/base.py", line 377, in _run_checks
        return checks.run_checks(**kwargs)
      File "/usr/local/lib/pulp/lib64/python3.6/site-packages/django/core/checks/registry.py", line 72, in run_checks
        new_errors = check(app_configs=app_configs)
      File "/usr/local/lib/pulp/lib64/python3.6/site-packages/django/core/checks/model_checks.py", line 168, in check_lazy_references
        return _check_lazy_references(apps)
      File "/usr/local/lib/pulp/lib64/python3.6/site-packages/django/core/checks/model_checks.py", line 163, in _check_lazy_references
        )), key=lambda error: error.msg)
      File "/usr/local/lib/pulp/lib64/python3.6/site-packages/django/core/checks/model_checks.py", line 162, in <genexpr>
        for func in apps._pending_operations[model_key]
      File "/usr/local/lib/pulp/lib64/python3.6/site-packages/django/core/checks/model_checks.py", line 157, in build_error
        return error_fn(model_key, func, args, keywords) if error_fn else None
      File "/usr/local/lib/pulp/lib64/python3.6/site-packages/django/core/checks/model_checks.py", line 107, in field_error
        'model': '.'.join(model_key),
    TypeError: sequence item 0: expected str instance, NoneType found

The reason is that those models are [re]defined in pulpcore-plugin, and have no app_label attached to them. This causes django lazy reference checks to fail at the migration generation time.

The workaround is to import directly from the pulpcore.

from pulpcore.plugin.models import Remote                                                                                                            
print(Remote._meta.app_label)  # None

from pulpcore.app.models import Remote                                                                                                               
print(Remote._meta.app_label)  # 'core'

Affected models (basically all models in pulpcore-plugin):
- Content
- ContentGuard
- Remote
- Publisher


Related issues

Related to Pulp - Issue #5355: Content model redefined in pulpcore-plugin is not the one exposed to Plugin APICLOSED - NOTABUGActions
Actions #1

Updated by ttereshc almost 5 years ago

  • Subject changed from Django makemigrations fail for realtions to Remote and Publisher from plugin API to Django makemigrations fail for relations to Remote and Publisher from plugin API
Actions #2

Updated by ttereshc almost 5 years ago

  • Description updated (diff)
Actions #3

Updated by ttereshc almost 5 years ago

FWIW, Content redifined in pulpcore-plugin works fine and it has the app_label.

from pulpcore.plugin.models import Content                                                                                                               
print(Content._meta.app_label)  # 'core'

Found a reason why Content model seemed to work, it's a bug I guess, filed https://pulp.plan.io/issues/5355

Actions #4

Updated by amacdona@redhat.com almost 5 years ago

  • Triaged changed from No to Yes
Actions #5

Updated by ttereshc over 4 years ago

  • Subject changed from Django makemigrations fail for relations to Remote and Publisher from plugin API to app_label is not set on the models in pulpcore-plugin
  • Description updated (diff)
  • Sprint/Milestone set to 3.0.0
Actions #6

Updated by ttereshc over 4 years ago

  • Related to Issue #5355: Content model redefined in pulpcore-plugin is not the one exposed to Plugin API added
Actions #7

Updated by ttereshc over 4 years ago

Actions #8

Updated by daviddavis over 4 years ago

  • Groomed changed from No to Yes
Actions #9

Updated by bmbouter over 4 years ago

  • Sprint set to Sprint 60
Actions #10

Updated by fao89 over 4 years ago

  • Status changed from NEW to ASSIGNED
  • Assignee set to fao89

Added by Fabricio Aguiar over 4 years ago

Revision 06c74125 | View on GitHub

Moving method from pulpcore-plugin models

Moving all the methods for: Content, ContentGuard, Remote and Publisher from pulpcore-plugin to pulpcore

closes #5353 https://pulp.plan.io/issues/5353

Actions #13

Updated by Anonymous over 4 years ago

  • Status changed from POST to MODIFIED
Actions #14

Updated by bmbouter over 4 years ago

  • Status changed from MODIFIED to CLOSED - CURRENTRELEASE

Also available in: Atom PDF