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

[BUG] Migrating with another database other than "default" #7774

Open
1 task
nzprog opened this issue Jan 21, 2024 · 4 comments
Open
1 task

[BUG] Migrating with another database other than "default" #7774

nzprog opened this issue Jan 21, 2024 · 4 comments

Comments

@nzprog
Copy link

nzprog commented Jan 21, 2024

Description

I am creating another database with tables not used with DjangoCMS and found a bug in the migration code.
see file .venv/lib/python3.11/site-packages/cms/migrations/0030_auto_20180810_0629.py

On line 29:

def set_page_url(apps, schema_editor):
    Page = apps.get_model('cms', 'Page')
    PageUrl = apps.get_model('cms', 'PageUrl')
    db_alias = schema_editor.connection.alias
    create_url = PageUrl.objects.using(db_alias).create

    for cms_page in Page.objects.all():
        for translation in cms_page.title_set.all():
            create_url(
                page=cms_page,
                slug=translation.slug,
                path=translation.path,
                managed=not bool(translation.has_url_overwrite),
                language=translation.language,
            )

Should include the alias for the current database

def set_page_url(apps, schema_editor):
    Page = apps.get_model('cms', 'Page')
    PageUrl = apps.get_model('cms', 'PageUrl')
    db_alias = schema_editor.connection.alias
    create_url = PageUrl.objects.using(db_alias).create

    for cms_page in Page.objects.using(db_alias).all():  # ADDED  .using(db_alias)
        for translation in cms_page.title_set.all():
            create_url(
                page=cms_page,
                slug=translation.slug,
                path=translation.path,
                managed=not bool(translation.has_url_overwrite),
                language=translation.language,
            )

Steps to reproduce

./manage migrate --database=OTHER_DATABASE

Expected behaviour

The migration should succeed.

Actual behaviour

Screenshots

Additional information (CMS/Python/Django versions)

Django 5.0.1
django-cms 4.1.0
python 3.11

Do you want to help fix this issue?

Ummm, the fix is in the comment above, if someone could put that in, it would be nice.

I tried to join the community but as per my other post, https://www.django-cms.org/en/sign-up-work-contribution/ catchup isn't working.

  • [ x ] Yes, I want to help fix this issue and I will join #workgroup-pr-review on Slack to confirm with the community that a PR is welcome.
  • No, I only want to report the issue.
@nzprog nzprog changed the title [BUG] Migrating with another database (clean of DjangoCMS tables) [BUG] Migrating with another database other than "default" Jan 21, 2024
@fsbraun
Copy link
Sponsor Member

fsbraun commented Jan 26, 2024

@nzprog Would you like to create a PR?

@nzprog
Copy link
Author

nzprog commented Jan 27, 2024

I've never done a pull request before, Are there steps for this for DjangoCMS?
Do I click on the green "New Pull Request" button under https://github.com/django-cms/django-cms/pulls ?

@fsbraun
Copy link
Sponsor Member

fsbraun commented Jan 27, 2024

Hi @nzprog !

Quick Guide to Contributing to django-cms

  1. Fork and Clone the Repository

    • Fork django-cms on GitHub.
    • Clone the fork to your local machine (git clone).
  2. Code and Test

    • Create a new branch for your changes.
    • Make changes, adhering to django-cms coding standards.
    • Test your changes locally.
  3. Submit a Pull Request

    • Commit your changes with a clear message.
    • Push to your fork and submit a PR to django-cms (GitHub will ask you to do so).
    • Respond to any review feedback.

See also: https://docs.django-cms.org/en/latest/contributing/code.html

@fsbraun
Copy link
Sponsor Member

fsbraun commented May 2, 2024

@nzprog Do you want to give it a try?

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

No branches or pull requests

2 participants