Skip to content

fix: correct sendercompid/targetcompid for incoming messages in PostgreSQLLog#738

Open
MubasherMajeed wants to merge 1 commit into
quickfix:masterfrom
MubasherMajeed:fix/postgresql-log-incoming-sender-target-swap
Open

fix: correct sendercompid/targetcompid for incoming messages in PostgreSQLLog#738
MubasherMajeed wants to merge 1 commit into
quickfix:masterfrom
MubasherMajeed:fix/postgresql-log-incoming-sender-target-swap

Conversation

@MubasherMajeed

Copy link
Copy Markdown

Problem

When PostgreSQLLog logs incoming messages via onIncoming(), the
sendercompid and targetcompid columns in messages_log are always
populated from the local SessionID object perspective.

This means if your session is SENDER -> TARGET, an incoming message
FROM the counterparty appears in the database as:

  • sendercompid = SENDER ← incorrect
  • targetcompid = TARGET ← incorrect

When it should be:

  • sendercompid = TARGET ← correct (actual sender)
  • targetcompid = SENDER ← correct (actual recipient)

This makes it impossible to distinguish incoming from outgoing messages
by querying sendercompid/targetcompid columns without parsing the raw
FIX text field.

Fix

Added isIncoming boolean parameter (default false) to insert().
When true (called from onIncoming()), getSenderCompID() and
getTargetCompID() are swapped to correctly reflect actual message
direction.

No breaking changes — existing behavior preserved for outgoing and
event logging.

Also Fixed

  1. Header guard order: #ifndef FIX_POSTGRESQLLOG_H was placed
    before the HAVE_POSTGRESQL check. Restored correct order so the
    HAVE_POSTGRESQL error fires before the include guard is evaluated.

  2. Incorrect class comment: PostgreSQLLogFactory was documented
    as "MySQL based implementation" — corrected to "PostgreSQL".

Testing

Verified against a live FIX acceptor (FIXT.1.1) with multiple sessions.
After fix, messages_log correctly shows:

  • Incoming: sendercompid = counterparty, targetcompid = local session
  • Outgoing: sendercompid = local session, targetcompid = counterparty

…reSQLLog

When logging incoming messages via onIncoming(), sendercompid and
targetcompid columns were always populated from the local SessionID
perspective, causing incoming messages to appear with incorrect
sender/target values in the messages_log table.

Fix: added isIncoming boolean parameter to insert(). When true,
getSenderCompID() and getTargetCompID() are swapped to correctly
reflect the actual message direction.

Also fixed incorrect class comment: PostgreSQLLogFactory was
documented as MySQL based implementation.
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.

1 participant