mommy.make() returns instance that did not go through any model manager, thus missing fields
cb109 opened this issue · 0 comments
cb109 commented
Instance returned by mommy.make()
differs from one queried inside the application when a custom default model manager is annotating the query.
Expected behavior
I am using a custom model manager in which default annotations are added to the queryset. I was expecting that the instance returned by mommy.make()
would include those annotated fields.
Actual behavior
The annotated fields are missing, since mommy.make()
does bypass tthe default (or any) model manager.
Reproduction Steps
- Define a model that uses a custom manager which adds an annotation, e.g. a simple alias to some other existing field.
- Call
mommy.make()
on that model. - The returned instance is missing the annotations.
from django.db import models
from model_mommy import mommy
class MovieManager(models.Manager):
def get_queryset(self):
return (
super(MovieManager, self).get_queryset()
.annotate(name=models.F('title'))
)
class Movie(models.Model):
title = models.CharField(max_length=30)
objects = MovieManager()
movie = mommy.make(Movie)
assert getattr(movie, 'name', None) is None
Versions
Python: 3.7
Django: 2.1
Model Mommy: 1.6.0