0

I am using pynamodb==3.3.3 to scan items with the attributes_to_get condition, but get an exception that I can't solve:

  File "/Users/user/Documents/project/script.py", line 250, in filter_writable_snapshots
    existing_snapshots = ItemSnapshot.scan(attributes_to_get=['id'])
  File "/Users/user/Documents/project/venv/lib/python3.7/site-packages/pynamodb/models.py", line 790, in scan
    filters=filters
  File "/Users/users/Documents/project/venv/lib/python3.7/site-packages/pynamodb/models.py", line 1050, in _build_filters
    raise ValueError("Attribute {0} specified for filter does not exist.".format(attr_name))
ValueError: Attribute attributes_to_get specified for filter does not exist.

The model has a field id.

from pynamodb.models import Model
from pynamodb.attributes import UnicodeAttribute

class ItemSnapshot(Model):
    class Meta:
        table_name = 'my_table'

    id = UnicodeAttribute(hash_key=True)
    other_field = UnicodeAttribute()

I am trying to load only the id field.

existing_snapshots = ItemSnapshot.scan(attributes_to_get=['id'])

Am I doing anything wrong here or why is the request crashing? The strack trace looks like it would try to find the attribute attributes_to_get which doesn't make any sense to me.

I already check that the class's attribute id does exist.

michaelbahr
  • 4,837
  • 2
  • 39
  • 75

1 Answers1

1

Method .scan() don't have parameter attributes_to_get. This available on .query() and .rate_limited_scan() methods.

Andrii Dubonos
  • 106
  • 1
  • 5
  • 1
    The method `.scan()` now has the parameter `attributes_to_get` that would project the provided field names as a list of str. https://pynamodb.readthedocs.io/en/latest/api.html#pynamodb.models.Model.scan – Aditya Shaw Sep 11 '22 at 17:47