Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native AOT support for DynamoDB #3475

Closed
dscpinheiro opened this issue Sep 13, 2024 Discussed in #3194 · 9 comments
Closed

Native AOT support for DynamoDB #3475

dscpinheiro opened this issue Sep 13, 2024 Discussed in #3194 · 9 comments
Labels
aot Ahead of Time feature-request A feature should be added or improved. p1 This is a high priority issue queued

Comments

@dscpinheiro
Copy link
Contributor

Discussed in #3194

Originally posted by mrdaghestani February 20, 2024
Hi,
I understand that NativeAOT is still a very new feature and probably most people prefer not to use it but, I wanted to suggest that we can talk about supporting it in DynamoDB SDK.

I was thinking it could be very useful if there was a source generator for mapping DynamoDB items into database models inside our code base so we can ignore using reflection and probably that would solve the support for NativeAOT.

What do you think? Is it something that you're thinking of implementing? If yes, what's the schedule?

Thank you

@dscpinheiro dscpinheiro added feature-request A feature should be added or improved. aot Ahead of Time labels Sep 13, 2024
@ashishdhingra ashishdhingra added needs-review p2 This is a standard priority issue labels Sep 16, 2024
@ashishdhingra
Copy link
Contributor

Needs to be reviewed by team for prioritization.

@Dreamescaper
Copy link
Contributor

Related to #2542

@bhoradc bhoradc added queued p1 This is a high priority issue and removed needs-review p2 This is a standard priority issue labels Sep 20, 2024
@petro2050
Copy link

@ashishdhingra @bhoradc is there any update on this? DynamoDB is the only blocker for me. :(

@normj
Copy link
Member

normj commented Dec 19, 2024

I made some progress putting a PR out for the DocumentModel library to be Native AOT. The PR is targeting our upcoming V4 version. #3583

@normj
Copy link
Member

normj commented Jan 16, 2025

Second PR #3606 merged into V4 that updates the DataModel also known as Object Persistence Model for Native AOT support. This change will go out as part of preview 6.

@normj
Copy link
Member

normj commented Feb 7, 2025

Closing the issue now that Native AOT support as been released as part of V4 preview 6. Follow the this GitHub issue for tracking the status of V4: #3362

@normj normj closed this as completed Feb 7, 2025
Copy link

github-actions bot commented Feb 7, 2025

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@Dreamescaper
Copy link
Contributor

Dreamescaper commented Feb 10, 2025

@normj
I've tested AOT integration with 4.0.0-preview.6.
There were no AOT warnings, however apparently, it doesn't support type properties and collection properties.

  1. Nested Types:
var nestedTypeId = Random.Shared.Next().ToString();
await context.SaveAsync(new TypeWithNestedTypeProperty
{
    Id = nestedTypeId,
    Name = "Test",
    SubType = new SubType() { SubName = "Subname" }
});
Console.WriteLine("Item saved.");

var nestedItem = await context.LoadAsync<TypeWithNestedTypeProperty>(nestedTypeId);
Console.WriteLine($"Item loaded: {nestedItem}");
Console.WriteLine($"SubType.SubName: {nestedItem.SubType.SubName}");

[DynamoDBTable("TestTable")]
class TypeWithNestedTypeProperty
{
    [DynamoDBHashKey]
    public string Id { get; set; }
    public string Name { get; set; }
    public SubType SubType { get; set; }
}

class SubType
{
    public string SubName { get; set; }
}

Result:

Unhandled Exception: System.InvalidOperationException: Type SubType is unsupported, it cannot be instantiated
   at Amazon.DynamoDBv2.DataModel.StorageConfig..ctor(Type) + 0x14f
   at Amazon.DynamoDBv2.DataModel.ItemStorageConfig..ctor(Type) + 0x12
   at Amazon.DynamoDBv2.DataModel.ItemStorageConfigCache.CreateStorageConfig(Type, String, DynamoDBFlatConfig) + 0x43
   at Amazon.DynamoDBv2.DataModel.ItemStorageConfigCache.GetConfig(Type, DynamoDBFlatConfig, Boolean) + 0x144
   at Amazon.DynamoDBv2.DataModel.DynamoDBContext.SerializeToDocument(Object, Type, DynamoDBFlatConfig) + 0x2c
   at Amazon.DynamoDBv2.DataModel.DynamoDBContext.ToDynamoDBEntry(SimplePropertyStorage, Object, DynamoDBFlatConfig, Boolean) + 0x125
   at Amazon.DynamoDBv2.DataModel.DynamoDBContext.PopulateItemStorage(Object, ItemStorage, DynamoDBFlatConfig, Boolean, Boolean) + 0xe6
   at Amazon.DynamoDBv2.DataModel.DynamoDBContext.ObjectToItemStorage(Object, Type, Boolean, DynamoDBFlatConfig) + 0x7e
   at Amazon.DynamoDBv2.DataModel.DynamoDBContext.<SaveHelperAsync>d__48.MoveNext() + 0x5d
  1. Collection property:
var listTypeId = Random.Shared.Next().ToString();
await context.SaveAsync(new TypeWithCollectionProperty
{
    Id = listTypeId,
    Name = "Test",
    Items = new List<string> { "1", "2", "3" }
});
Console.WriteLine("Item saved.");

var collectionItem = await context.LoadAsync<TypeWithCollectionProperty>(listTypeId);
Console.WriteLine($"Item loaded: {collectionItem}");
Console.WriteLine($"Items: {string.Join(",", collectionItem.Items)}");

[DynamoDBTable("TestTable")]
class TypeWithCollectionProperty
{
    [DynamoDBHashKey]
    public string Id { get; set; }
    public string Name { get; set; }
    public List<string> Items { get; set; }
}

Result:

Unhandled Exception: System.InvalidOperationException: Cannot instantiate type System.Collections.Generic.List`1[[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]
   at Amazon.DynamoDBv2.DataModel.Utils.InstantiateHelper(Type, Type[][], Object[]) + 0x119
   at Amazon.DynamoDBv2.DataModel.Utils.ItemsToIList(Type, IEnumerable`1, Object&) + 0x42
   at Amazon.DynamoDBv2.Converter.TryFromEntry(DynamoDBEntry, Type, Object&) + 0x79
   at Amazon.DynamoDBv2.Converter.FromEntry(DynamoDBEntry, Type) + 0x39
   at Amazon.DynamoDBv2.DataModel.DynamoDBContext.FromDynamoDBEntry(SimplePropertyStorage, DynamoDBEntry, DynamoDBFlatConfig) + 0x7f
   at Amazon.DynamoDBv2.DataModel.DynamoDBContext.PopulateInstance(ItemStorage, Object, DynamoDBFlatConfig) + 0xc4
   at Amazon.DynamoDBv2.DataModel.DynamoDBContext.DocumentToObject(Type, ItemStorage, DynamoDBFlatConfig) + 0x47
   at Amazon.DynamoDBv2.DataModel.DynamoDBContext.DocumentToObject[T](ItemStorage, DynamoDBFlatConfig) + 0x32
   at Amazon.DynamoDBv2.DataModel.DynamoDBContext.<LoadHelperAsync>d__57`1.MoveNext() + 0x1c4

Attaching sample project:
DdbAORRepro.zip

@dscpinheiro
Copy link
Contributor Author

@Dreamescaper I cut a new issue here: #3646, we'll take a look (and thanks for the reproduction project).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aot Ahead of Time feature-request A feature should be added or improved. p1 This is a high priority issue queued
Projects
None yet
Development

No branches or pull requests

6 participants