I am running into the same issue...
I can persist user scoped model fine but cannot read it back..even if I hard code the id as a constant i.e. "bob" when writing and then reading the model back...
` public static void persistState(Session session) {
// take care of state
try {
String userId = session.getUser().getUserId();
//AWSDynamoStateHandler can't handle IDs with "." convert them to "-"
userId = userId.replaceAll("\.", "-");
logger.info("persistState() persisting state for user: " + userId);
final AlexaStateHandler handler = new AWSDynamoStateHandler(session);
AlexaUser activeUser = handler.readModel(AlexaUser.class, "bob")
.orElse(handler.createModel(AlexaUser.class, "bob"));
........
activeUser.saveState();
}
} catch (AlexaStateException ase) {
logger.error("Exception attempting to persist user data to dynamoDB ", ase);
}
}`
(i've confirmed that the data is written to DyanmoDB:
I see:
amazon-user-id
model-class :
state: "id" : "bob"
)
reading the value back with id "bob" doesn't load the model ...
` public static Optional restoreState(SpeechletRequestEnvelope requestEnvelope) {
Session session = requestEnvelope.getSession();
String userId = session.getUser().getUserId();
userId = userId.replaceAll("\\.", "-");
logger.info("restoreState(): attempting to restore state for userId: " + userId);
Optional<AlexaUser> activeUser = Optional.empty();
try {
final AlexaStateHandler handler = new AWSDynamoStateHandler(requestEnvelope.getSession());
activeUser = handler.readModel(AlexaUser.class, "bob");
if (activeUser.isPresent()) {
logger.info(
"restoreState() Found previous session for this user, restoring session attributes from AlexaUser: "
.....//DO work here....
} catch (AlexaStateException e) {
logger.error("Exception while attempting to load user's saved search attributes from dynamoDB: " + userId, e);
}
return activeUser;
}`
I've narrowed it down to where it short-circuits the readModel logic...i am not sure if this is a bug or not...
AWSDynamoStateHandler line# 251 readModel(...) calls getItems(..) and passes "false" as the 2nd argument:
final List<Map<String, AttributeValue>> readRequests = getItems(model, false);
getItems then adds primary keys as attribute and only loads USER scoped attribute if "withState" is true..but 'false' was passed..so it returns an empty list..which cases readModel to log line # 265 and return an empty Optional....