signumsoftware / extensions

Set of modules that complements Signum Framework: Authorization, Charting, ControlPanels, Mailing, Processes, Scheduled Tasks, Disconnected, User Queries...

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

EmailTemplateEntity.Messages -> MList notification of parent Issue (Entity.GetParentEntity())

modma opened this issue · comments

Hi, another problem with a Migration of my project, in this case is the work of the extensions parsing the MList notification, in my scenario:

tempBlah = new EmailTemplateEntity
                {
                    Active = true,
                    Name = "Liquidaciones Blah",
                    From = new EmailTemplateContactEntity
                    {
                        DisplayName = "Blah Hispania",
                        EmailAddress = "blah@blah.es"
                    },
                    StartDate = DateTime.Now.TrimToMinutes(),
                    IsBodyHtml = true,
                    SystemEmail = SystemEmailLogic.ToSystemEmailEntity(typeof(LiquidacionesColaboradoresMail)),
                    Query = QueryLogic.GetQueryEntity(typeof(SettlementEntity)),
                    Messages =
                    {
                        new EmailTemplateMessageEntity(CultureInfoLogic.GetCultureInfoEntity("es"))
                        {
                            //Template = tempAMV,
                            Subject = "Informe Blah @[Entity.CreationDate.Date]",
                            Text = @"<p>Estimado @[Supplier.FiscalEntity.FiscalName],<p><br/> Blah Blah"
                        }
                    }
                }.Save();
            }

the Messages validation at Save() causes 2 referece null exceptions in Subject & Text, this errors is caused in EmailTemplateLogic.EmailTemplateMessageText_StaticPropertyValidation at message.GetParentEntity() because the MList<> is not transfered the parent entity...
A bad test fix with i made to test the problem is this modification of EmailTemplateEntity.Messages this this code (old framework system usage)

		[NotNullable]
		MList<EmailTemplateMessageEntity> messages;
		[NotifyCollectionChaMessages nged, NotifyChildProperty]
        public MList<EmailTemplateMessageEntity> Messages
        {
            get
            {
                if (messages == null) Messages = new MList<EmailTemplateMessageEntity>();
                return messages;
            }
            set { Set(ref messages, value); }
        }

in bad practice now corrects the notification, but seems a potencial bug in the framework parsing the .SetParentEntity() in the MList...

any effective solution? thanks

error

If you look at ModifiableEntity, the attribute NotifyChildPropertyAttribute controls setting the ParentEntity.

Looks like Messages already has this attribute so in theory should work. Are you in the very last version?

...maybe with this tip you can debug the problem and fin the issue?

yes, I integrated the lastest framework & extensions in the application this morning, to test if recentlies changes of the extensions (a week aprox), fixes it this problem, of course the problem still remains

Found! look at DashboardEntity, it has a special constructor that calls RebindEvents. EmailTemplateEntity needs the same.

Don't know why this bug doesn't cause problems in our code...

Can you check it and make a PR?

Thanks

Yes, effectively this code fixed the problem, i'll create a PR in a moment adding this:

        public EmailTemplateEntity()
        {
            RebindEvents();
        }

        public EmailTemplateEntity(object queryName) : this()
        {
            this.queryName = queryName;
        }

Last thing, explicitly in with cases, besides this, needs to add RebindEvents();? thanks

This is the order of execution when constructing an entity:

  • ModifiableEntity field initializarions
  • ModifiableEntity constructor (calls RebindEvents)
  • EmailTemplateEntity field initialization
  • EmailTemplateEntity constructor

So when RebindEvents is called, the fields in the descendent classes are not set.

So until someone comes with a better solution, classes with MLists and NotifyChildProperty need RevindEvents

ok i publish the PR, thank you very much!
PD: saludos de parte de Adrian y Nuria

Thanks for the PR and writing the issue in English

PD: Hey, saludos a los tres :)