litestar-org / polyfactory

Simple and powerful factories for mock data generation
https://polyfactory.litestar.dev/
MIT License
988 stars 78 forks source link

feat(sqlfactory): support nested type in pg.array types and others #530

Closed wangxin688 closed 3 months ago

wangxin688 commented 3 months ago

enhance sqlalchemy factory support postgresql dialects.

Description

wangxin688 commented 3 months ago

seems main was broken for mypy.

tests/test_recursive_models.py:56: error: Non-overlapping identity check (left operand type: "PydanticNode", right operand type: "type[_Sentinel]")  [comparison-overlap]
wangxin688 commented 3 months ago

seems there's no way to reflect JSON or JSONB 's python type. so should I remove JSON, JSONB in types maping? or treat it as dict by default?. becuase JSON and JSONB also support list[Any]? what's you guys ideas?

peterschutt commented 3 months ago

seems there's no way to reflect JSON or JSONB 's python type. so should I remove JSON, JSONB in types maping? or treat it as dict by default?. becuase JSON and JSONB also support list[Any]? what's you guys ideas?

Yeah, array is valid json - I'd have to defer to @guacs on what is the right way to handle this for polyfactory.

wangxin688 commented 3 months ago

seems there's no way to reflect JSON or JSONB 's python type. so should I remove JSON, JSONB in types maping? or treat it as dict by default?. becuase JSON and JSONB also support list[Any]? what's you guys ideas?

Yeah, array is valid json - I'd have to defer to @guacs on what is the right way to handle this for polyfactory.

Just my ideas, maybe not the best way. add a migac method to sqlafactory, such as __default_json_type__: ClassVar[type] = dict, but it can be change as other type when inherit from factory. then handle the JSON type by magic method definition.

wangxin688 commented 3 months ago

seems there's no way to reflect JSON or JSONB 's python type. so should I remove JSON, JSONB in types maping? or treat it as dict by default?. becuase JSON and JSONB also support list[Any]? what's you guys ideas?

Yeah, array is valid json - I'd have to defer to @guacs on what is the right way to handle this for polyfactory.

Just my ideas, maybe not the best way. add a migac method to sqlafactory, such as __default_json_type__: ClassVar[type] = dict, but it can be change as other type when inherit from factory. then handle the JSON type by magic method definition.

I have remove JSON and JSONB types due to uncertain python types.

wangxin688 commented 3 months ago

BTW, I didnot see types.Uuid in get_sqlalchemy_types, after my local test, it's well suited with types.Uuid: uuid4 add to return dict.

guacs commented 3 months ago

@wangxin688 thanks for this!

For the JSON and JSONB, I think we can default to a random dictionary. If the users need something other than the deafult, they can override the get_sqlalchemy_types or get_provider_map.

wangxin688 commented 3 months ago

looks like main branch is broken for lint again. @guacs JSON has been added back. pls review

wangxin688 commented 3 months ago

looks like main branch is broken for lint again. @guacs JSON has been added back. pls review

may I ask why lint rule is checked for all files not newly changed files?

wangxin688 commented 3 months ago

looks like main branch is broken for lint again. @guacs JSON has been added back. pls review

I executed pre-commit run --all-files on my PC, no issues were reported. As it's not related for this PR, how to skip linting checking? --

guacs commented 3 months ago

looks like main branch is broken for lint again. @guacs JSON has been added back. pls review

I executed pre-commit run --all-files on my PC, no issues were reported. As it's not related for this PR, how to skip linting checking? --

Skipping it isn't possible though it can be merged even if the linting fails. I'll fix the linting issues and try to make it only lint the changes files (sometime this week) and once that's merged, we can merge that into this branch?

github-actions[bot] commented 3 months ago

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