You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
formoduleinlist(MANAGER.astroid_cache.values()):
# only load model classes from modules which match the module in# which *we think* they are defined. This will prevent inferring# other models of the same name which are found elsewhere!ifmodel_nameinmodule.localsandmodule.name.endswith(module_name):
class_defs=_get_model_class_defs_from_module(module, model_name, module_name)
ifclass_defs:
returniter([class_defs[0].instantiate_class()])
module.locals contains class names the way they appear in the model files, for example 'MyModel': [<ClassDef.MyModell.193 at 0x7fe5ebc42560>].
However, if I define my Foreign Key with the target myapp.mymodel, which is strictly valid in Django, model_name in module.locals will fail because model_name contains mymodel and module.locals has a key MyModel.
I am using the following versions:
django 4.2.20
pylint 3.3.6
pylint_django 2.6.1
I have no idea what would be the best way to improve this check.
A naive approach would be to do:
if any([model_name.lower() == local_model.lower() for local_model in module.locals]) and module.name.endswith(module_name)
but I am not sure about the performance of this.
The text was updated successfully, but these errors were encountered:
Although Django seems to support it, pylint_django does not find models which are specified lowercase and this is due to the following code block: https://github.com/pylint-dev/pylint-django/blob/master/pylint_django/transforms/foreignkey.py#121
module.locals
contains class names the way they appear in the model files, for example'MyModel': [<ClassDef.MyModell.193 at 0x7fe5ebc42560>]
.However, if I define my Foreign Key with the target
myapp.mymodel
, which is strictly valid in Django,model_name in module.locals
will fail becausemodel_name
containsmymodel
andmodule.locals
has a keyMyModel
.I am using the following versions:
I have no idea what would be the best way to improve this check.
A naive approach would be to do:
if any([model_name.lower() == local_model.lower() for local_model in module.locals]) and module.name.endswith(module_name)
but I am not sure about the performance of this.
The text was updated successfully, but these errors were encountered: