Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: generate() missing 1 required positional argument: 'params' #787

Closed
jaap3 opened this issue Oct 5, 2020 · 4 comments
Closed

Comments

@jaap3
Copy link
Contributor

jaap3 commented Oct 5, 2020

After upgrading from 3.0.1 to 3.1 I suddenly get a TypeError: generate() missing 1 required positional argument: 'params'.

I have a factory.LazyAttribute that calls factory.Faker('safe_email').generate() conditionally. This worked before and now raises a TypeError.

This seems to be caused by commit f0a4ef0. Would it be possible to make params optional?

@rbarrois
Copy link
Member

rbarrois commented Oct 5, 2020

Hi! Thanks for the report.

The factory.Faker.generate is a private API; its direct use is not supported.

I'm a bit surprised by your issue though, the API is supposed to be foo = factory.Faker('safe_email'), not foo = factory.LazyAttribute(lambda o: factory.Faker('safe_email').generate()) — the former is much shorter ;)

@jaap3
Copy link
Contributor Author

jaap3 commented Oct 5, 2020

Sorry, I was in a hurry when I wrote this bug report. The full code is something like this:

emails = factory.LazyAttribute(lambda o: [factory.Faker('safe_email').generate()] if o.some_boolean_field else [])

I'm not sure why it's written like this (I'm not the author of that bit of code).

@rbarrois
Copy link
Member

rbarrois commented Oct 5, 2020

I see ;)

The "proper" way would be:

emails = factory.Maybe(
    factory.SelfAttribute('some_boolean_field'),
    factory.List([factory.Faker('safe_email')]),
    [],
)

I guess we should make it easier to find in the docs; and maybe easier to write too…

However, there seems to be a bug deeper down (see #786) in the Faker code which might fix the code you've got.

@jaap3
Copy link
Contributor Author

jaap3 commented Oct 6, 2020

Thanks for the snippet of the "proper" way. I'll update our code so we don't use a private API anymore.

I don't think there's anything to do on the factory_boy side, so I'll close this issue. Thanks again!

@jaap3 jaap3 closed this as completed Oct 6, 2020
rbarrois added a commit that referenced this issue Dec 23, 2020
Unrolling the extra context for a declaration might depend on the
declaration's internals; that's typically the case with factory.Maybe:
the inner declarations might depend on the actual declaration used.

This adds `evaluate_pre` and a `evaluate_post` entrypoints to
declarations, more readable with regard to which build phase they are
used in.

Each of those will perform unrolling before calling the semi-public
actual function entrypoint (self.evaluate() for evaluate_pre,
self.call() for evaluate_post).

As a side effect, this fixes the issues with factory.Faker() when called
inside a factory.Maybe().

Closes #785 #786 #787 #788 #790 #796.
rbarrois added a commit that referenced this issue Dec 23, 2020
Unrolling the extra context for a declaration might depend on the
declaration's internals; that's typically the case with factory.Maybe:
the inner declarations might depend on the actual declaration used.

This adds `evaluate_pre` and a `evaluate_post` entrypoints to
declarations, more readable with regard to which build phase they are
used in.

Each of those will perform unrolling before calling the semi-public
actual function entrypoint (self.evaluate() for evaluate_pre,
self.call() for evaluate_post).

As a side effect, this fixes the issues with factory.Faker() when called
inside a factory.Maybe().

Closes #785 #786 #787 #788 #790 #796.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants