0

I am getting FATAL: database "xxxxxxxxx" does not exist during the loading of py.test. This is coming from the loading of the admin forms, where by I have a queryset being passed to a ModelChoiceField

class CustomChoiceField(forms.ModelChoiceField):
    def __init__(self, queryset=None, *args, **kwargs):
        return super().__init__(SomeModel.objects.limited_qs(), *args, **kwargs)


class SomeModelForm(forms.ModelForm):
    some_model = CustomChoiceField()

    class Meta:
        model = SomeModel


class SomeModelAdmin(admin.ModelAdmin):
    form = SomeModelForm

I've tried this with

formfield_overrides = { models.ForiegnKey : {'queryset': ... } }

all result in the same problem with py.test

EDIT

Having the queryset either in the __init__ method or in formfield_overrides also breaks the migrations.

Note: these all work exactly how I want them to on the server - they just prevent me for running any tests.

How do I get this to pass (w/o conditionally registering my admin stuff ;_; I like tdd)

yarbelk
  • 7,215
  • 6
  • 29
  • 37
  • What's you test code like? – ljk321 Apr 24 '15 at 07:01
  • I have 200 tests, running from integration tests on an API to unit tests on stubbed user models. The stack trace comes from the ```__init__``` where the queryset is created. It doesn't even load the tests themselves - just errors out. The root is ```python3.4/site-packages/_pytest/config.py``` – yarbelk Apr 24 '15 at 07:47

1 Answers1

0

I had a similar problem, in my case, the problem was that in my SomeModel.objects.limited_qs(), I was calling another queryset like:

self.filter(another_model=AnotherModel.objects.get(xxx=1))

So, to build the queryset a call to database was executed before the test database creation, causing the "FATAL database does not exist"

Gleber
  • 151
  • 4