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

Use of itertools.count to generate record ids in Recipe #123

Closed
formacube opened this issue Oct 27, 2020 · 8 comments · Fixed by #253
Closed

Use of itertools.count to generate record ids in Recipe #123

formacube opened this issue Oct 27, 2020 · 8 comments · Fixed by #253
Labels
bug Something isn't working

Comments

@formacube
Copy link

formacube commented Oct 27, 2020

Hi,

itertools.count does not seem to be working in recipe or in a direct make statement

when I declare:

import itertools as it
baker.make('Play',  puzzle_id=it.count(start=1), _quantity=7)

or
fake_play = Recipe(Play, puzzle_id=it.count(start=1))

I expected puzzle_id to take incremental values 1,2,3, ... 7

Instead, I receive an error message:

TypeError: int() argument must be a string, a bytes-like object or a number, not 'itertools.count'

I have tried different things but I don't really see what is happening as itertools.cycle is working well.

There seem to be nothing on the internet about it, not on the documentation. So I would assume it normally works

Could you help me out?

Versions

Python:Python 3.7.4
Django: 2.2.7
Model Bakery:1.0.2

@berinhard
Copy link
Member

Hi @formacube, thanks for your issue. Did you tried to use sequences instead? You can use it as:

from model_bakery.recipes import seq
fake_play = Recipe(Play, puzzle_id=seq(1))

This is the correct way to bakery's recipes with iterables.

@formacube
Copy link
Author

you are right !
I lost more than one hour for nothing.

I only used seq so far as part of a string.
I didn't realized it could also be used for other variable types.

Thanks a lot Berinhard

@berinhard
Copy link
Member

You're welcome! I'm glad model bakery is being useful for you =)

@formacube formacube changed the title itertools.count Use of itertools.count to generate record ids in Recipe Oct 27, 2020
@formacube
Copy link
Author

model bakery is extremely useful !

for the record: from model_bakery.recipe

however, I receive now the following error when using seq:

TypeError: int() argument must be a string, a bytes-like object or a number, not 'itertools._tee'

My goal is to fill-in the id number corresponding to a foreign key:

class Play(models.Model): puzzle = models.ForeignKey( Puzzle, on_delete=models.CASCADE, related_name='plays')

Have you ever performed that ?
Is it working for you ?
or how should I do that?

@formacube
Copy link
Author

Hi Bernardo,

By applying your proposition, I found out it is not working.
I defined my question a bit better, but as I'm not able to re-open the issue, I'm not sure you are alerted.

@berinhard berinhard reopened this Oct 29, 2020
@berinhard
Copy link
Member

@formacube I'm preparing myself for Brazil's PyCon (we call it Python Brasil) which will begin next monday. Because of that I'm with a lot of stuff in my plate now, but as soon as things calm down I'll revisit this issue. Probably this will happen during python brasil's sprints days.

@berinhard
Copy link
Member

Anyway, I reopened this issue so I won't forget to read it again =)

@formacube
Copy link
Author

Thanks a lot, and have a nice event

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants