You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a DynamoDB table that stores jobs opening details.
Below is how I configured my DynamoDB table:
I am now trying to retrieve all items using the PynamoDB library from one of my index recruiter_index using the below code:
opening.py
from pynamodb.models import Model
from pynamodb.attributes import UnicodeAttribute
from kink import di, inject
from models.recruiter_index import RecruiterIndex
@inject
class Opening(Model):
"""
A DynamoDB Opening Table
"""
class Meta:
table_name = "mo-bizin-travay"
region = "eu-west-1"
recruiter_index = RecruiterIndex()
id = UnicodeAttribute(hash_key=True)
title = UnicodeAttribute()
posted_date = UnicodeAttribute()
recruiter = UnicodeAttribute()
updated_at = UnicodeAttribute()
recruiter_index.py
from pynamodb.indexes import GlobalSecondaryIndex, AllProjection
from pynamodb.attributes import UnicodeAttribute
class RecruiterIndex(GlobalSecondaryIndex):
"""
This class represents a global secondary index
"""
class Meta:
# index_name is optional, but can be provided to override the default name
index_name = "recruiter_index"
read_capacity_units = 2
write_capacity_units = 1
# All attributes are projected
projection = AllProjection()
# This attribute is the hash key for the index
# Note that this attribute must also exist
# in the model
recruiter = UnicodeAttribute()
main.py
def main(event, context):
for item in Opening.recruiter_index.query("MCB"):
print("Item queried from index: {0}".format(item))
But i am getting the below error:
Traceback (most recent call last):
File "/Users/mervin.hemaraju/Projects/Personal/mo-bizin-travay/runner.py", line 8, in <module>
main(EVENT, CONTEXT)
File "/Users/mervin.hemaraju/Projects/Personal/mo-bizin-travay/di.py", line 32, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/mervin.hemaraju/Projects/Personal/mo-bizin-travay/main.py", line 12, in main
for item in Opening.recruiter_index.query("MCB"):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/mervin.hemaraju/Projects/Personal/mo-bizin-travay/.venv/lib/python3.11/site-packages/pynamodb/indexes.py", line 89, in query
return self._model.query(
^^^^^^^^^^^^^^^^^^
File "/Users/mervin.hemaraju/Projects/Personal/mo-bizin-travay/.venv/lib/python3.11/site-packages/pynamodb/models.py", line 661, in query
hash_key = cls._indexes[index_name]._hash_key_attribute().serialize(hash_key)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'serialize'
The text was updated successfully, but these errors were encountered:
Traceback (most recent call last):
File "/Users/mervin.hemaraju/Projects/Personal/mo-bizin-travay/iac/scripts/scraper/runner.py", line 9, in <module>
main(EVENT, CONTEXT)
File "/Users/mervin.hemaraju/Projects/Personal/mo-bizin-travay/iac/scripts/scraper/models/core/di.py", line 35, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/mervin.hemaraju/Projects/Personal/mo-bizin-travay/iac/scripts/scraper/test.py", line 17, in main
for item in Opening.query(recruiter_index == "MCB"):
^^^^^^^^^^^^^^^
NameError: name 'recruiter_index' is not defined
I have a DynamoDB table that stores jobs opening details.
Below is how I configured my DynamoDB table:
I am now trying to retrieve all items using the
PynamoDB
library from one of my indexrecruiter_index
using the below code:opening.py
recruiter_index.py
main.py
But i am getting the below error:
The text was updated successfully, but these errors were encountered: