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

Fix don't serialize DbContext #117

Conversation

joelweiss
Copy link
Contributor

PR for #100

Copy link
Owner

@RehanSaeed RehanSaeed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one very quick question in the review. Apart from that, it all looks good to me. I'll merge and release soon after.

@@ -329,6 +329,11 @@ private ReflectionInfo GenerateReflectionInfoForType(Type valueType)
{
try
{
if (values.ContainsKey(property.Name))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain this change a little? I think it's just making sure that no duplicates are added. Is that something that can happen?

Perhaps a unit test would also help explain and test it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @RehanSaeed, I reviewed the code and since we iterate over properties name generated by reflection there is no possibility of duplicates.
I would suggest removing the code unless you can demonstrate in the unit test that there is a possibility to introduce duplicates here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I should have made this a separate PR...

There is a possibility of having the same property name twice if the property is hidden.

The first commit was this check and the test as well.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot on this Joel! If this was a separate PR, I think we could have merged now but no worries!

I'm not sure if we should ignore the property if we find a duplicate. We should probably add something to the end of the name and add it, so we don't lost anything. Thoughts @krajek?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had the same thoughts yesterday.
For sure, dropping one of the properties is not the way to go.

We already had similar issue with Type property name.

if (propertiesBag.ContainsProperty("Type"))
            {
                if (!propertiesBag.ContainsProperty("$Type"))
                {
                    propertiesBag.AddProperty("$Type", valueType.FullName);
                }
                else
                {
                    // If both "Type" and "$Type" are present
                    // we just give up appending exception type
                }
            }
            else
            {
                propertiesBag.AddProperty("Type", valueType.FullName);
            }

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory, there could be more than one property like this, so we should append something random to the end of the property name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this was a separate PR, I think we could have merged now but no worries!

It would still have to wait on the separate PR 😜, I noticed it because of this


What do you guys think of prepending the Namespace.TypeName if there is a collision?

private class ReflectionPropertyInfo
{
    public string Name { get; set; }
    public Type DeclaringType { get; set; }
    public Func<object, object> Getter { get; set; }
}
...
var key = values.ContainsKey(property.Name) ? $"{property.DeclaringType.FullName}.{property.Name}" : property.Name;
values.Add(key, destructuredValue);

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds like a great idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@RehanSaeed
Copy link
Owner

I forgot to mention that we should also mention that this NuGet package exists in the ReadMe.md file.

@RehanSaeed
Copy link
Owner

As thanks, I've listed you as a contributor on the front page:

https://github.com/RehanSaeed/Serilog.Exceptions/blob/master/README.md

@joelweiss
Copy link
Contributor Author

I forgot to mention that we should also mention that this NuGet package exists in the ReadMe.md file.

Done, I added a note about Serilog.Exceptions.SqlServer as well, feel free to change the documentation to your liking.

@RehanSaeed
Copy link
Owner

RehanSaeed commented Jul 5, 2019

The build is failing. I think that is because The Microsoft.SourceLink.GitHub package is being duplicated from the project reference.

@krajek Are you happy? It looks good to me.

@RehanSaeed RehanSaeed merged commit 1c7cdb3 into RehanSaeed:master Jul 11, 2019
@RehanSaeed
Copy link
Owner

Merged. I'll fix up the boken build and release. Thanks for your contribution.

@joelweiss joelweiss deleted the Fix-Dont-Deserialize-DbContext-Issue-100 branch July 12, 2019 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants