First of all, I think there is an incorrect design in popstore.CustomerServices.register#Customer
[1] as it should login immediately after creating a user, otherwise the code in the rest of the service will not execute. Anyway, when I correct this logic by setting loginAfterCreate: true
I immediately face an exception [3]. This exception is coming from the line that tries to get the user login key [2]
This is not the first time I face such bugs. There seems to be some bugs in the framework around making consecutive calls to the entity engine.
Any thoughts on how to resolve this?
[1] <service-call name="mantle.party.PartyServices.create#Account" in-map="context + [roleTypeId:'Customer', loginAfterCreate:false]"/>
[2] <set field="apiKey" from="ec.user.getLoginKey()"/>
[3]
20:09:35.852 WARN 112797691-42 o.moqui.i.e.EntityValueImpl Error creating [moqui.security.UserLoginKey: [loginKey:a36fde8ad2199983287c18d3ebd0cf65733d5b4aea470cc64525e5b80f898bc7, userId:100153, fromDate:2021-06-12 20:09:35.85, thruDate:2021-06-18 20:09:35.85, null:null, lastUpdatedStamp:2021-06-12 20:09:35.85]] tx a Bitronix Transaction with GTRID [3132372E302E302E310000017A013347EA00000015], status=ACTIVE, 1 resource(s) enlisted (started Sat Jun 12 20:09:35 AST 2021) con Group: transactional, Con: a ConnectionJavaProxy of a JdbcPooledConnection from datasource transactional_DS in state ACCESSIBLE with usage count 1 wrapping org.postgresql.xa.PGXAConnection@189b5fb1 on Pooled connection wrapping physical connection org.postgresql.jdbc.PgConnection@4510ddaa: org.postgresql.util.PSQLException: ERROR: insert or update on table "user_login_key" violates foreign key constraint "userloginkeyuseraccount"
Detail: Key (user_id)=(100153) is not present in table "user_account".