Skip to content

Python SDK: select parameter of where forces certain fields to be included #15

Description

@ccecora

Hi all!

Running into an issue with the where method. If I use the select parameter, I get the following stack trace when including a small subset of fields:

from pokemontcgsdk import Set

Set.where(select="id,name")
DefaultValueNotFoundError                 Traceback (most recent call last)
File ~/.local/share/virtualenvs/TCDB-rYsgZGZb/lib/python3.12/site-packages/dacite/core.py:72, in from_dict(data_class, data, config)
     71 try:
---> 72     value = get_default_value_for_field(field, field_type)
     73 except DefaultValueNotFoundError:

File ~/.local/share/virtualenvs/TCDB-rYsgZGZb/lib/python3.12/site-packages/dacite/dataclasses.py:21, in get_default_value_for_field(field, type_)
     20     return None
---> 21 raise DefaultValueNotFoundError()

DefaultValueNotFoundError: 

During handling of the above exception, another exception occurred:

MissingValueError                         Traceback (most recent call last)
Cell In[30], line 1
----> 1 Set.where(select="id,name")

File ~/.local/share/virtualenvs/TCDB-rYsgZGZb/lib/python3.12/site-packages/pokemontcgsdk/set.py:30, in Set.where(**kwargs)
     28 @staticmethod
     29 def where(**kwargs):
---> 30     return QueryBuilder(Set).where(**kwargs)

File ~/.local/share/virtualenvs/TCDB-rYsgZGZb/lib/python3.12/site-packages/pokemontcgsdk/querybuilder.py:40, in QueryBuilder.where(self, **kwargs)
     37 for key, value in kwargs.items():
     38     self.params[key] = value
---> 40 return self.all()

File ~/.local/share/virtualenvs/TCDB-rYsgZGZb/lib/python3.12/site-packages/pokemontcgsdk/querybuilder.py:63, in QueryBuilder.all(self)
     60 if self.transform:
     61     response = [self.transform(i) for i in response]
---> 63 list.extend([from_dict(self.type, item) for item in response])
     65 if fetch_all:
     66     self.params['page'] += 1

File ~/.local/share/virtualenvs/TCDB-rYsgZGZb/lib/python3.12/site-packages/dacite/core.py:76, in from_dict(data_class, data, config)
     74         if not field.init:
     75             continue
---> 76         raise MissingValueError(field.name)
     77 if field.init:
     78     init_values[field.name] = value

MissingValueError: missing value for field "images"

If I keep adding fields to the select parameter that are deemed missing in each subsequent stacktrace, I will eventually get a success:

Set.where(select="id,name,images,legalities,printedTotal,releaseDate,series,total,updatedAt")
[
   Set(id='base2', images=SetImage(symbol='https://images.pokemontcg.io/base2/symbol.png', logo='https://images.pokemontcg.io/base2/logo.png'), legalities=Legality(unlimited='Legal', expanded=None, standard=None), name='Jungle', printedTotal=64, ptcgoCode=None, releaseDate='1999/06/16', series='Base', total=64, updatedAt='2020/08/14 09:35:00'),
   Set(id='ecard2', images=SetImage(symbol='https://images.pokemontcg.io/ecard2/symbol.png', logo='https://images.pokemontcg.io/ecard2/logo.png'), legalities=Legality(unlimited='Legal', expanded=None, standard=None), name='Aquapolis', printedTotal=147, ptcgoCode=None, releaseDate='2003/01/15', series='E-Card', total=182, updatedAt='2020/08/14 09:35:00'),
   ...
]

My suspicion is that these fields are mandatory. Does not seem like this functionality is intentional, maybe worth mentioning what fields must be entered by default in the meantime?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions