polyfactory icon indicating copy to clipboard operation
polyfactory copied to clipboard

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

Open wangxin688 opened this issue 1 year ago • 7 comments

enhance sqlalchemy factory support postgresql dialects.

Description

  • support postgresql dialects types: JSON, JSONB and HSTORE type
  • support nested pg.ARRAY types, such as ARRAY(INET), ARRAY(MACADDR) and etc

Closes

wangxin688 avatar Apr 30 '24 03:04 wangxin688

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 avatar Apr 30 '24 03:04 wangxin688

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?

wangxin688 avatar Apr 30 '24 04:04 wangxin688

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.

peterschutt avatar Apr 30 '24 04:04 peterschutt

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 avatar Apr 30 '24 05:04 wangxin688

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 avatar Apr 30 '24 10:04 wangxin688

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.

wangxin688 avatar Apr 30 '24 10:04 wangxin688

@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.

vkcku avatar May 02 '24 18:05 vkcku

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

wangxin688 avatar May 05 '24 13:05 wangxin688

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 avatar May 05 '24 13:05 wangxin688

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? --

wangxin688 avatar May 07 '24 13:05 wangxin688

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?

vkcku avatar May 08 '24 10:05 vkcku

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

github-actions[bot] avatar May 09 '24 02:05 github-actions[bot]