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

RuntimeError: dictionary keys changed during iteration #43

Open
jpic opened this issue Jul 27, 2020 · 1 comment
Open

RuntimeError: dictionary keys changed during iteration #43

jpic opened this issue Jul 27, 2020 · 1 comment

Comments

@jpic
Copy link

jpic commented Jul 27, 2020

With this code:

class Industry(TranslationModel):
    name = models.CharField(max_length=255)
    profession_set = models.ManyToManyField(
        'Profession',
        through='IndustryProfession',
    )

    def __str__(self):
        return self.name

    class Meta:
        translatable_fields = ('name',)

Getting a shell exception:

In [5]: Industry.objects.language('fr').filter(name='Armement')                                                                                     
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-5-6ae5df24159f> in <module>
----> 1 Industry.objects.language('fr').filter(name='Armement')

~/.local/lib/python3.8/site-packages/nece/managers.py in filter(self, *args, **kwargs)
     80     def filter(self, *args, **kwargs):
     81         if not self.is_default_language(self._language_code):
---> 82             for key, value in kwargs.items():
     83                 if key.split('__')[0] in self.model._meta.translatable_fields:
     84                     del kwargs[key]

RuntimeError: dictionary keys changed during iteration

Not sure what I'm doing wrong, also got some weird results here:


In [14]: Industry.objects.filter(name='Armament').first().translations                                                                              
Out[14]: {'name': {'en': 'Armament', 'fr': 'Armement'}}

In [15]: test = Industry.objects.filter(name='Armament').first()                                                                                    

In [16]: test.language('fr')                                                                                                                        
Out[16]: <Industry: Armament>

In [17]: test.name                                                                                                                                  
Out[17]: 'Armament'   <-------------- not the fr translation
@xavfernandez
Copy link

#42 should fix this.

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