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

ValueError with Mutable Default in Dataclasses in types.py #66

Open
flettl2 opened this issue Jan 4, 2024 · 0 comments
Open

ValueError with Mutable Default in Dataclasses in types.py #66

flettl2 opened this issue Jan 4, 2024 · 0 comments

Comments

@flettl2
Copy link

flettl2 commented Jan 4, 2024

Environment:

  • driftpy version: 0.7.7
  • Python version: 3.11.5
  • OS: Pop!_OS 22.04 LTS

To Reproduce the error during the execution, run the following code:

import os
from anchorpy import Wallet
from driftpy.keypair import load_keypair
from driftpy.drift_client import DriftClient
from solana.rpc.async_api import AsyncClient
import asyncio

keypair_file = os.path.expanduser('~/.config/solana/my-keypair.json')
keypair = load_keypair(keypair_file)
wallet = Wallet(keypair)

url = 'https://api.mainnet-beta.solana.com'
connection = AsyncClient(url)

drift_client = DriftClient(connection, wallet, 'mainnet')

async def initialize_user():
    tx_sig = await drift_client.initialize_user(sub_account_id=0, name='toly')

asyncio.run(initialize_user())

Expected Behavior:
I want to initialize a user

Actual Behavior:
Encountered a ValueError: mutable default <class 'sumtypes.NONE'> for field post_only is not allowed: use default_factory

Error Message/Stack Trace:
Traceback (most recent call last): File "/home/[username]/[project_directory]/initial_play.py", line 10, in <module> from driftpy.drift_client import DriftClient File "/home/[username]/[python_environment]/site-packages/driftpy/drift_client.py", line 22, in <module> from driftpy.account_subscription_config import AccountSubscriptionConfig File "/home/[username]/[python_environment]/site-packages/driftpy/account_subscription_config.py", line 6, in <module> from driftpy.accounts.bulk_account_loader import BulkAccountLoader File "/home/[username]/[python_environment]/site-packages/driftpy/accounts/__init__.py", line 1, in <module> from .get_accounts import * File "/home/[username]/[python_environment]/site-packages/driftpy/accounts/get_accounts.py", line 7, in <module> from driftpy.types import * File "/home/[username]/[python_environment]/site-packages/driftpy/types.py", line 336, in <module> @dataclass File "/home/[username]/[python_environment]/site-packages/dataclasses.py", line 1230, in dataclass return wrap(cls) File "/home/[username]/[python_environment]/site-packages/dataclasses.py", line 1220, in wrap return _process_class(cls, init, repr, eq, order, unsafe_hash, File "/home/[username]/[python_environment]/site-packages/dataclasses.py", line 958, in _process_class cls_fields.append(_get_field(cls, name, type, kw_only)) File "/home/[username]/[python_environment]/site-packages/dataclasses.py", line 815, in _get_field raise ValueError(f'mutable default {type(f.default)} for field ' ValueError: mutable default <class 'sumtypes.NONE'> for field post_only is not allowed: use default_factory

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