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

feat: check if fields declared on the factory belong to the model #405

Conversation

johnraz
Copy link
Contributor

@johnraz johnraz commented Oct 13, 2023

Pull Request Checklist

  • New code has 100% test coverage
  • (If applicable) The prose documentation has been updated to reflect the changes introduced by this PR
  • (If applicable) The reference documentation has been updated to reflect the changes introduced by this PR
  • Pre-Commit Checks were ran and passed
  • Tests were ran and passed

Description

This change will detect whenever a field is defined on the factory that doesn't exist on the model.

  • If the field is using an explicit construct (like Use, PostGenerated, ...) it will raise an exception
  • in other case it will only output a warning
  • classmethods / methods / functions and fields starting with __ are not checked because they can't be easily differentiated

Close Issue(s)

Fixes #400

polyfactory/factories/base.py Outdated Show resolved Hide resolved
polyfactory/factories/base.py Outdated Show resolved Hide resolved
polyfactory/factories/base.py Outdated Show resolved Hide resolved
@guacs
Copy link
Member

guacs commented Oct 14, 2023

@johnraz, the approach seems good to me. Thank you for this :)

@JacobCoffee JacobCoffee changed the title [DRAFT] Check if fields declared on the factory belong to the model Check if fields declared on the factory belong to the model Oct 15, 2023
@JacobCoffee
Copy link
Member

You can mark a PR as draft instead of having to edit the title when ready 😛
image

@JacobCoffee JacobCoffee changed the title Check if fields declared on the factory belong to the model feat: check if fields declared on the factory belong to the model Oct 15, 2023
@JacobCoffee
Copy link
Member

Also please see #406 with sourcery-suggested changes if applicable

@johnraz
Copy link
Contributor Author

johnraz commented Oct 16, 2023

You can mark a PR as draft instead of having to edit the title when ready 😛 image

TIL, not using Github that much lately 😇

@johnraz
Copy link
Contributor Author

johnraz commented Oct 16, 2023

Also please see #406 with sourcery-suggested changes if applicable

It's not relevant anymore but thanks for the pointer 👍

@johnraz johnraz force-pushed the Issue-400-raise-error-when-defining-non-model-fields branch from 006f3d8 to 0e6462d Compare October 16, 2023 09:38
docs/usage/declaring_factories.rst Outdated Show resolved Hide resolved
polyfactory/factories/base.py Show resolved Hide resolved
polyfactory/factories/base.py Show resolved Hide resolved
tests/test_factory_fields.py Outdated Show resolved Hide resolved
@johnraz johnraz requested a review from guacs October 17, 2023 14:32
docs/usage/configuration.rst Outdated Show resolved Hide resolved
@github-actions
Copy link

Documentation preview will be available shortly at https://litestar-org.github.io/polyfactory-docs-preview/405

@guacs
Copy link
Member

guacs commented Oct 18, 2023

I'm not seeing any unresolved reviews, but GitHub isn't letting me merge :/

@litestar-org/maintainers, could one of you merge this?

@guacs
Copy link
Member

guacs commented Oct 18, 2023

@johnraz thank you for this and thank you for being so patient with my suggestions!

@all-contributors add @johnraz for code, docs, test

@allcontributors
Copy link
Contributor

@guacs

I couldn't determine any contributions to add, did you specify any contributions?
Please make sure to use valid contribution names.

I've put up a pull request to add @johnraz! 🎉

@johnraz johnraz requested a review from guacs October 18, 2023 14:19
@johnraz
Copy link
Contributor Author

johnraz commented Oct 18, 2023

@guacs don't you need to re-approve ? It seems to say that one change is still requested based on your previous review 🙂

@guacs
Copy link
Member

guacs commented Oct 18, 2023

@guacs don't you need to re-approve ? It seems to say that one change is still requested based on your previous review 🙂

Oh I'm an idiot. I didn't realize I never approved it :P

@guacs guacs merged commit 5fefa41 into litestar-org:main Oct 18, 2023
19 checks passed
@johnraz
Copy link
Contributor Author

johnraz commented Oct 18, 2023

Thanks for the support with this PR btw 🎉 🙏

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

Successfully merging this pull request may close these issues.

Enhancement: issue an error when defining attributes that are not part of the model
5 participants