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

TypeError: 'NoneType' object is not iterable #2

Open
Renkineko opened this issue Oct 12, 2024 · 0 comments
Open

TypeError: 'NoneType' object is not iterable #2

Renkineko opened this issue Oct 12, 2024 · 0 comments

Comments

@Renkineko
Copy link

Renkineko commented Oct 12, 2024

Hi.

I'm trying to use MPTT with parler to translate my website, more exactly the FAQ on it. The models are quite simples, but I didn't manage to succeed to configure it without django-categories-i18n. Google is failing me, Django copilot also... So I'm opening this issue, sorry about that.

Here are my models:

from django.db import models
from mptt.models import TreeManyToManyField
from parler.models import TranslatableModel, TranslatedFields
from django.utils.translation import gettext_lazy
from categories_i18n.models import Category as BaseCategoryI18n

from martor.models import MartorField

class CategoryI18n(BaseCategoryI18n):
    css_classes = models.CharField(gettext_lazy("classes CSS"), max_length=256, blank=True)
    
class QuestionI18n(TranslatableModel):
    SRC_DISCORD = 'discord'
    SRC_FACEBOOK = 'facebook'
    SRC_FORUM = 'forum'
    SRC_MAIL = 'mail'
    SRC_PDF = 'pdf'
    source_type_choices = (
        (SRC_PDF, gettext_lazy('FAQ PDF')),
        (SRC_FORUM, gettext_lazy('Forum')),
        (SRC_DISCORD, gettext_lazy('Discord')),
        (SRC_FACEBOOK, gettext_lazy('Facebook')),
        (SRC_MAIL, gettext_lazy('Mail')),
    )
    
    TranslatedFields(
        question = models.CharField(gettext_lazy("question"), max_length=512),
        answer = MartorField(gettext_lazy("answer"), blank=True, null=True),
        source_type = models.CharField(gettext_lazy('source type'), max_length=8, choices=source_type_choices, blank=True, null=True),
    )
    gm = models.BooleanField(gettext_lazy('filtre MJ'), blank=True, default=False)
    v1 = models.BooleanField(gettext_lazy('compatible v1'), blank=True, default=True)
    v1_5 = models.BooleanField(gettext_lazy('compatible v1.5'), blank=True, default=True)
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)
    category = TreeManyToManyField(
        CategoryI18n,
        verbose_name=gettext_lazy("catégorie(s)"),
        related_name="questions",
        blank=True
    )

I can create CategoryI18n, no problem here. The problem is when I try to create a question, even without a category (I added the blank=True to see if a question without category would work... The answer is no :( )

In a shell:

from gm.models.faq import QuestionI18n
q = QuestionI18n()
q.question='test'
q.save()

It output this exception:

TypeError                                 Traceback (most recent call last)
Cell In[4], line 1
----> 1 q.save()

File ~/git/knightools/venv/lib/python3.10/site-packages/parler/models.py:717, in TranslatableModelMixin.save(self, *args, **kwargs)
    712 # Makes no sense to add these for translated model
    713 # Even worse: mptt 0.7 injects this parameter when it avoids updating the lft/rgt fields,
    714 # but that misses all the translated fields.
    715 kwargs.pop("update_fields", None)
--> 717 self.save_translations(*args, **kwargs)

File ~/git/knightools/venv/lib/python3.10/site-packages/parler/models.py:759, in TranslatableModelMixin.save_translations(self, *args, **kwargs)
    756 # Copy cache, new objects (e.g. fallbacks) might be fetched if users override save_translation()
    757 # Not looping over the cache, but using _parler_meta so the translations are processed in the order of inheritance.
    758 local_caches = self._translations_cache.copy()
--> 759 for meta in self._parler_meta:
    760     local_cache = local_caches[meta.model]
    761     translations = list(local_cache.values())

TypeError: 'NoneType' object is not iterable

It occurs too deeply for my knowledge and thus I have no idea about how to workaround this problem.

Python 3.10.12
Django 5.1.1
django-categories-i18n 2.0
django-mptt 0.16.0
django-parler 2.3

Any clue? I'm beginning to think I will have to duplicate all my databases and have multiple instances of my project running, one by language... But I would really prefer to make MPTT works (and also rest and elasticsearch, but that I will try once I succeed with MPTT)

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

1 participant