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

Reseeding doesn't return consistent data for some providers #1313

Closed
Svenito opened this issue Jan 31, 2023 · 7 comments
Closed

Reseeding doesn't return consistent data for some providers #1313

Svenito opened this issue Jan 31, 2023 · 7 comments
Assignees
Labels
bug Unexpected behaviour and bugs

Comments

@Svenito
Copy link

Svenito commented Jan 31, 2023

Bug report

What's wrong

generic.file.file_name() does not provide the same data when reseeding the provider.

In [5]: g = Generic()

In [8]: g.reseed(1)

In [9]: g.file.file_name()
Out[9]: 'conducted.md'

In [10]: g.reseed(1)

In [11]: g.file.file_name()
Out[11]: 'encouraged.md'

How is that should be

When reseeding the values returned should be the same.
It seems that the extension remains the same on each reseed but the filename differs each time.
Not all providers have this issue. So far I've only noticed this happening with file.file_name

System information

mimesis 7.0.0
python 3.9.9
windows 11

@lk-geimfari lk-geimfari added the bug Unexpected behaviour and bugs label Feb 1, 2023
@lk-geimfari
Copy link
Owner

lk-geimfari commented Feb 1, 2023

This is probably a bug. I'll fix this. Thank you for report!

@lk-geimfari
Copy link
Owner

This problem requires quite a serious overhaul of some providers.

This is because some providers under the hood use other providers (for example Internet) and when the ".reseed()" method is called it reseeding only the original provider.

@lk-geimfari
Copy link
Owner

@sobolevn I apologize for the inconvenience, but do you have any eligant solution for this?

@Svenito
Copy link
Author

Svenito commented Mar 31, 2023

I hope you don't mind me making a couple of suggestions here:

One option would be to override the reseed method for any class that has sub-providers, and reseed those providers there.

Another option would be to iterate over the attributes of a class in the reseed base class method, and reseed any attribute that is a subclass or instance of BaseProvider

The latter might not be as clean, but it would help prevent human error of forgetting to reseed a sub-provider. Plus only requires a change to the BaseProvider

Just some ideas to throw into the ring.

I just tested this the latest master and the issue is no longer there.

>>> g.file.file_name()
'charge.ppt'
>>> g.reseed(1)
>>> g.file.file_name()
'charge.ppt'
>>> g.reseed(1)
>>> g.file.file_name()
'charge.ppt'
>>> g.reseed(1)
>>> g.file.file_name()
'charge.ppt'

Closing issue. Thank you for looking into this

@Svenito Svenito closed this as completed Mar 31, 2023
@lk-geimfari
Copy link
Owner

I fixed the issue only for File, but the bug itself is still there, so I'll reopen this issue.

@lk-geimfari lk-geimfari reopened this Mar 31, 2023
Svenito added a commit to Svenito/mimesis that referenced this issue Apr 1, 2023
This patch will iterate over the subproviders on a provider and reseed
them. Otherwise providers that rely on other providers to generate data
will not return consistent data when reseeded with the same value.

Fix lk-geimfari#1313
Svenito added a commit to Svenito/mimesis that referenced this issue Apr 1, 2023
This patch will iterate over the subproviders on a provider and reseed
them. Otherwise providers that rely on other providers to generate data
will not return consistent data when reseeded with the same value.

Fix lk-geimfari#1313
Svenito added a commit to Svenito/mimesis that referenced this issue Apr 1, 2023
This patch will iterate over the subproviders on a provider and reseed
them. Otherwise providers that rely on other providers to generate data
will not return consistent data when reseeded with the same value.

Fix lk-geimfari#1313
@Svenito
Copy link
Author

Svenito commented Apr 1, 2023

Hi, I tentatively submitted a PR that reseeds all related providers on the BaseProvider.
Hopefully this is an acceptable way to solve the issue

@lk-geimfari
Copy link
Owner

I've fixed this bug. Thank you, @Svenito.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected behaviour and bugs
Projects
None yet
Development

No branches or pull requests

3 participants