dynamodb-toolbox icon indicating copy to clipboard operation
dynamodb-toolbox copied to clipboard

Query and Scan do not parse `sets`.

Open KodiVerse opened this issue 3 years ago • 10 comments

We have noticed that while using the functions scan and query any set attributes do not seem to be parsed correctly. They come back as a DynamoDBSet and not as a list. However, when we use the get function, all the attributes that are returned appear to have been parsed correctly (including sets).

Is this by design? Perhaps I missed a setting. Any advice would be greatly appreciated.

Get result:

{ id: 'id', someSet: [ 'one', 'two' ] }

Scan and Query result:

{ id: 'id', someSet: [Set] }

KodiVerse avatar Apr 20 '21 22:04 KodiVerse

What is the status on this?

simlu avatar Jun 18 '21 16:06 simlu

Any update on this?

simlu avatar Jul 09 '21 18:07 simlu

Hey just following up if there is any update on this?

KodiVerse avatar Sep 01 '21 16:09 KodiVerse

:wave:

simlu avatar Oct 01 '21 16:10 simlu

ping

simlu avatar Dec 01 '21 17:12 simlu

More than a year and no reaction for this issue, so disappointing :-(

aldex32 avatar Jun 01 '22 15:06 aldex32

👋

simlu avatar Aug 01 '22 23:08 simlu

@naorpeled - can you take a look at this?

jeremydaly avatar Aug 02 '22 01:08 jeremydaly

@naorpeled - can you take a look at this?

Sure!

naorpeled avatar Aug 02 '22 16:08 naorpeled

I've played around with some data and found the following:

  • when querying/scanning a table, each item in the table needs the '_et' (entity name) field in order for it to be parsed properly, because we're checking the mapping of that specific entity.

  • when using the get operation, because the scope is a specific entity, we're looking at that entity's mapping and parse the fields according to it, even when it doesn't have the '_et' field explicitly.

So I'm guessing that what happened was that somehow the '_et' field was missing.

What we can do is if someone attempts to query a table using the entity (Entity.query(...)), we'll enforce the mapping check to be against that specific entity's mapping, imo it's not something that I'd expect the library to do. Another solution would be to ignore the mapping and convert the property's value to an array if its .values is an array, which is basically checking wether the value is a DDBSet.

What do you think? @jeremydaly @krackerman

naorpeled avatar Aug 05 '22 20:08 naorpeled

@naorpeled Thank you for taking a look.

Just so I understand what is happening. get will automatically parse because it is scoped to that specific Entity. Like a Customer as an example. If you are using a Single Table desgin, Scan and Query can return different entities (Customers, Businesses, Orders, etc). So Scan and Query will not automatically parse if the _et field is not set on that Entity. Is this true?

We are not using a Single Table design so we did not set the _et field. So this feels like we are just missing setting.

KodiVerse avatar Aug 08 '22 17:08 KodiVerse

@naorpeled Thank you for taking a look.

Just so I understand what is happening. get will automatically parse because it is scoped to that specific Entity. Like a Customer as an example. If you are using a Single Table desgin, Scan and Query can return different entities (Customers, Businesses, Orders, etc). So Scan and Query will not automatically parse if the _et field is not set on that Entity. Is this true?

We are not using a Single Table design so we did not set the _et field. So this feels like we are just missing setting.

Exactly.

naorpeled avatar Aug 08 '22 17:08 naorpeled

@naorpeled This is exactly what I needed thank you for all the help.

KodiVerse avatar Aug 08 '22 18:08 KodiVerse

@naorpeled This is exactly what I needed thank you for all the help.

You're welcome! :)

I'll be closing this issue for now.

naorpeled avatar Aug 08 '22 18:08 naorpeled

Looks like this is not working as expected. We are trying to add entity into scan and query, but it doesn't seem to fix the issue.

entity: The name of a table Entity to evaluate filters and attributes against.

Am I missing something here? Will look into creating a minimal test case next.

simlu avatar Aug 08 '22 23:08 simlu

For reference, this doesn't work: https://github.com/blackflux/aws-sdk-wrap/pull/2151/files

We'll try and get a minimal test case in so it's easier to reason about. Don't have an eta for that though

simlu avatar Aug 10 '22 15:08 simlu

Looks like this is not working as expected. We are trying to add entity into scan and query, but it doesn't seem to fix the issue.

entity: The name of a table Entity to evaluate filters and attributes against.

Am I missing something here? Will look into creating a minimal test case next.

I see that in the code, we're using the entity name for building filter expressions and projections but not for parsing the attributes of the returned items.

Not sure whether I'd change that logic because you might have several entities in your table and enforcing the parsing of all items would potentially break the parsing of the entities that are not provided in the entity parameter.

At the moment what you can do is add the entity name (_et by default) field with the entity name and it would be parsed properly, just make sure to map the specific set field's type to set.

Wdyt?

naorpeled avatar Aug 13 '22 10:08 naorpeled

At the moment what you can do is add the entity name (_et by default) field with the entity name and it would be parsed properly, just make sure to map the specific set field's type to set.

@naorpeled Just so I understand - we would have to rewrite all our millions of dynamodb records to accomplish this, correct?

I would be great if there was a way to tell dynamodb-toolbox to "parse all responses as a certain entity". Maybe this is a separate option that is passed in?

Edit: Maybe a parseAs option?

simlu avatar Aug 18 '22 22:08 simlu

At the moment what you can do is add the entity name (_et by default) field with the entity name and it would be parsed properly, just make sure to map the specific set field's type to set.

@naorpeled Just so I understand - we would have to rewrite all our millions of dynamodb records to accomplish this, correct?

I would be great if there was a way to tell dynamodb-toolbox to "parse all responses as a certain entity". Maybe this is a separate option that is passed in?

Edit: Maybe a parseAs option?

Unfortunately with the current implementation that is correct.

Will discuss this with @jeremydaly and see what fits best for this scenario.

naorpeled avatar Aug 18 '22 23:08 naorpeled

Sorry for being late to this conversation, but any Entity written to the table using the toolbox should get an _et value (unless you disabled it). If it doesn't have that value, then, yes, we would need to add some sort of parseAs option, but the idea is not to need that. Let me dig into the code a bit and see if we're missing something else here.

jeremydaly avatar Aug 24 '22 21:08 jeremydaly

FYI Yes, we did disable that since we only have one entity type per table.

simlu avatar Aug 24 '22 21:08 simlu

^ :wave: Any update on this? Cheers!

simlu avatar Sep 01 '22 16:09 simlu

👋

simlu avatar Sep 14 '22 17:09 simlu

Can we please reopen this ticket?

simlu avatar Nov 01 '22 16:11 simlu

@simlu I'm working on it now, will open a PR asap!

naorpeled avatar Nov 05 '22 00:11 naorpeled

This works great now! Thank you for the fix!

simlu avatar Mar 23 '23 16:03 simlu