MagicTheGathering / mtg-sdk-python

Magic: The Gathering SDK - Python
MIT License
255 stars 45 forks source link

Color Identity as filter not working #19

Open timboudreau25 opened 5 years ago

timboudreau25 commented 5 years ago

It appears the query ignores color identity filters. For example:

Card.where(power = 15).where(color_identity = 'G').all()

Returns four cards, only one of which has green (the other three are None). This happens even when the other cards are an actual color and not just colorless. When mixing and matching queries, the color identity is always ignored.

Reid-E commented 5 years ago

Each Resource class (Card, Set, Supertype, Type, Subtype, Changelog) passes the kwargs you give it to QueryBuilder, which uses those kwargs to make API calls. As a result, you need to use the API parameters and not the class fields for your kwards in Resource.where()

The API uses colorIdentity, not color_identity, because the API doesn't adhere to Python conventions.

You can test the query resulting from your Card.where() call by entering it into your browser at https://api.magicthegathering.io/v1/%r?%p1=v1&p2=v2... %r is the resource name (plural) (ex. cards, sets) %pn and %vn are the parameters and values (ex. power=15, colorIdentity='G')

Here's the API result of the query your function call would produce.

Try Card.where(power=15, colorIdentity='G').all()

You can see the API result from your browser