agateblue / agateblue/django-dynamic-preferences

'NoneType' object has no attribute '__name__'

Aberta
#173 12 comentários 0 reações 0 responsáveis Ver no GitHub
Linguagem predominante
Python
Estrelas
359
Forks
86
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

I have installed the library, define a preference , but when try to use it in my code, I got this.

```
File "/home/gonzalo/Playground/tektank-ws/tektank/tektank/apps/entities/models.py", line 27, in _validate_dob
oag = global_preferences['general__oldest_allowed_age']
File "/home/gonzalo/.virtualenvs/tektank-ws/lib/python3.6/site-packages/dynamic_preferences/managers.py", line 29, in __getitem__
return self.get(key)
File "/home/gonzalo/.virtualenvs/tektank-ws/lib/python3.6/site-packages/dynamic_preferences/managers.py", line 133, in get
return self.from_cache(section, name)
File "/home/gonzalo/.virtualenvs/tektank-ws/lib/python3.6/site-packages/dynamic_preferences/managers.py", line 63, in from_cache
self.get_cache_key(section, name), CachedValueNotFound)
File "/home/gonzalo/.virtualenvs/tektank-ws/lib/python3.6/site-packages/dynamic_preferences/managers.py", line 57, in get_cache_key
return 'dynamic_preferences_{0}_{1}_{2}'.format(self.model.__name__, section, name)
AttributeError: 'NoneType' object has no attribute '__name__'

```

This is my code:

```
from dynamic_preferences.registries import global_preferences_registry
global_preferences = global_preferences_registry.manager()

def _validate_dob(value):
oag = global_preferences['general__oldest_allowed_age']
yag = global_preferences['general__youngest_allowed_age']
if not oag <= value <= yag:
raise ValidationError(
_("Date must be between %(oag)s and %(yag)s"),
code='invalid_model_data',
params={'oag':oag.strftime("%x"), 'yag':yag.strftime("%x")},
)

```
I found this issue, but it does not give the solution with code.
https://github.com/EliotBerriot/django-dynamic-preferences/issues/163

Guia de contribuição

Abrir o guia de contribuição

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.