Opened 8 years ago

Closed 8 years ago

#28173 closed Bug (invalid)

Occasional FieldError for field that really does exist

Reported by: Evan Heidtmann Owned by: nobody
Component: Database layer (models, ORM) Version: 1.9
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Evan Heidtmann)

My app, running in production with uwsgi, very occasionally will crash because of a FieldError on a (valid) reverse ForeignKey relationship field. Without any code changes, other requests will succeed. Tests that cover this code path always pass.

The two models are in different apps. Both apps are listed in INSTALLED_APPS and the calling module imports both models modules at top level. One of the models is "replaceable" but I'm using the original model (it's oauth2_provider.Application)

# app1/models.py
class A(models.Model):
    name = models.CharField(max_length=20)

def get_A_model():
    # ... some thirdparty code for replaceable models ...

# app2/models.py
class B(models.Model):
    myname = models.CharField(max_length=20)
    a = models.ForeignKey('app1.A')

# app2/views.py
import app1.models as app1_models
from . import models

def view(request):
   # This line crashes with "FieldError: Cannot resolve keyword 'b' into field. Choices are: ..."
    qs = app1_models.get_A_model().objects.filter(b__myname='larry')

This smells like some kind of deployment issue (code loading too late or not at all?) but if so, I don't know how to debug. Thanks for taking a look and let me know what I can do to gather more helpful information.

Change History (3)

comment:1 by Evan Heidtmann, 8 years ago

Description: modified (diff)

comment:2 by Evan Heidtmann, 8 years ago

Description: modified (diff)

comment:3 by Tim Graham, 8 years ago

Component: UncategorizedDatabase layer (models, ORM)
Resolution: invalid
Status: newclosed
Type: UncategorizedBug

Please see TicketClosingReasons/UseSupportChannels for ways to get help. The discussion in #27365 may help you.

Note: See TracTickets for help on using tickets.
Back to Top