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

Support Tuple[] and NamedTuple types #66

Open
pirate opened this issue May 21, 2024 · 0 comments
Open

Support Tuple[] and NamedTuple types #66

pirate opened this issue May 21, 2024 · 0 comments

Comments

@pirate
Copy link

pirate commented May 21, 2024

This is a separate issue to add NamedTuple/Tuple support, broken out from #65

I have this Pydantic model that I want to allow users to edit in the UI:

from typing import NamedTuple

class SemVer(NamedTuple):
    major: int
    minor: int = 0
    patch: int = 0
    
    def __new__(cls, *args, **kwargs):
		# allow creating from string SemVer('1.2.3') or SemVer(1, 2, 3)
		if len(args) == 1 and isinstance(args, str):
			args = (int(chunk) for chunk in args[0].split('.'))
        return cls(*args, **kwargs)
	
class Dependency(models.Model):
    min_version: SemVer = SchemaField(default=(0,0,1))

Currently trying to render the Admin UI produces a number of errors in the UI, but the key one for this issue is:
image


(!) Error: Error while creating EditorState: Invalid schema: Schema of type 'array' must have a key called 'items'

I have also seen this error when trying to nest SemVer inside a different Pydantic BaseModel:
image

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

No branches or pull requests

1 participant