M
M
Maxim Yakovenko2020-12-11 20:23:18
Python
Maxim Yakovenko, 2020-12-11 20:23:18

How to set a field in Gino model when creating it via Factory?

There are two factories:

class UserFactory(factory.Factory):
    class Meta:
        model = models.User
   .....

class ProfileFactory(factory.Factory):
    class Meta:
        model = models.Profile

    user = factory.SubFactory(UserFactory)


When assembling the model via ProfileFactory.build(), Gino.CrudModelit cannot set the value for the `user` attribute for the Profile model, i.e. there are lines:
setattr(self._instance, key, value)
value = getattr(self._instance, value_from)[key]  # value_from = __values__

; which work for primitives (str, int), but do not work for related models.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question