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

BaseModel.__init__() takes 1 positional argument but 2 were given #25

Open
changuncle opened this issue Jul 14, 2024 · 1 comment
Open

Comments

@changuncle
Copy link

changuncle commented Jul 14, 2024

class Address(BaseModel):
street: Optional[str]
number: Optional[int]
zip_code: Optional[int]
city: Optional[str]

class PersonInfo(BaseModel):
name: Optional[str] = None
age: Optional[int] = None
address: Optional[Address] = None

class PublicPersonInfo(BaseModel):
name: Optional[str] = None
address: Optional[Address] = None

if name == 'main':
address = Address(street="Main Street",number=1,zip_code=100001,city='Test City')

info = PersonInfo(name='John Doe', age=35, address=address)

# default deepcopy behavior
public_info = mapper.to(PublicPersonInfo).map(info)
print("Target public_info.address is same as source address: ", address is public_info.address)
# Target public_info.address is same as source address: False

# disable deepcopy
public_info = mapper.to(PublicPersonInfo).map(info, use_deepcopy=False)
print("Target public_info.address is same as source address: ", address is public_info.address)
# Target public_info.address is same as source address: True

When run these code an exception was throwed, please help me to figure out an solution, thanks

@changuncle changuncle changed the title type(obj)() how to create an instance BaseModel.__init__() takes 1 positional argument but 2 were given Jul 15, 2024
@Nivyaal-zenity
Copy link

im having the same issue how did you solve it?

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

2 participants