{"record":{"id":"f14005e430494893","repo":"we-promise/sure","slug":"invalid-ibkr-flex-xml-missing-account-identifier","errorCode":null,"errorMessage":"Invalid IBKR Flex XML: missing account identifier in FlexStatement.","messagePattern":"Invalid IBKR Flex XML: missing account identifier in FlexStatement\\.","errorType":"exception","errorClass":"IbkrItem::ReportParser::ParseError","httpStatus":null,"severity":"error","filePath":"app/models/ibkr_item/report_parser.rb","lineNumber":60,"sourceCode":"      @document.xpath(\"//FlexStatement\")\n    end\n\n    def root_metadata\n      node_attributes(@document.at_xpath(\"//FlexQueryResponse\"))\n    end\n\n    def parse_statement(statement)\n      statement_data = node_attributes(statement)\n      account_information = node_attributes(statement.at_xpath(\"./AccountInformation\"))\n      position_values = section_rows(statement, POSITION_VALUE_CONTAINER_NAMES, POSITION_VALUE_ROW_NAMES)\n      cash_report = section_rows(statement, CASH_REPORT_CONTAINER_NAMES, CASH_REPORT_ROW_NAMES)\n      equity_summary_in_base = section_rows(statement, EQUITY_SUMMARY_CONTAINER_NAMES, EQUITY_SUMMARY_ROW_NAMES)\n      open_positions = section_rows(statement, OPEN_POSITION_CONTAINER_NAMES, OPEN_POSITION_ROW_NAMES)\n      trades = section_rows(statement, TRADES_CONTAINER_NAMES, TRADE_ROW_NAMES)\n      cash_transactions = section_rows(statement, CASH_TRANSACTION_CONTAINER_NAMES, CASH_TRANSACTION_ROW_NAMES)\n      account_id = account_information[\"account_id\"].presence || statement_data[\"account_id\"]\n\n      raise ParseError, \"Invalid IBKR Flex XML: missing account identifier in FlexStatement.\" if account_id.blank?\n\n      currency = account_information[\"currency\"].presence&.upcase || \"USD\"\n      report_date = open_positions.filter_map { |row| parse_date(row[\"report_date\"]) }.max ||\n        equity_summary_in_base.filter_map { |row| parse_date(row[\"report_date\"]) }.max ||\n        parse_date(statement_data[\"to_date\"]) ||\n        Date.current\n\n      {\n        ibkr_account_id: account_id,\n        name: account_id,\n        currency: currency,\n        cash_balance: extract_cash_balance(cash_report, currency),\n        current_balance: extract_total_balance(position_values, cash_report, currency),\n        report_date: report_date,\n        statement: statement_data,\n        cash_report: cash_report,\n        equity_summary_in_base: equity_summary_in_base,\n        open_positions: open_positions,","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/we-promise/sure/blob/e69894adb92547273377398c15f45c979cd9416a/app/models/ibkr_item/report_parser.rb#L42-L78","documentation":"parse_statement requires an account identifier for each FlexStatement: it takes account_information['account_id'] from the statement's AccountInformation node, falling back to the statement's own account_id attribute. If both are blank, ParseError raises because the parsed account cannot be keyed to an IBKR account id.","triggerScenarios":"A FlexStatement whose AccountInformation section is missing or lacks the account id attribute, and whose statement-level attributes also lack it — typically a Flex Query definition that omits the AccountInformation columns.","commonSituations":"Custom Flex Query definitions skipping AccountInformation; IBKR changing attribute names/casing so normalization no longer matches; partial reports during IBKR incidents.","solutions":["Open the Flex Query definition in IBKR Portal and make sure the AccountInformation section (with accountId) is included in the query","Inspect the raw statement XML to confirm which node/attribute carries the account id","If IBKR renamed the attribute, update the parser's attribute normalization to match the new name"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"rescue IbkrItem::ReportParser::ParseError; for the 'missing account identifier' variant, capture the statement's attribute keys (redacted) in a debug log and point the user at their Flex Query's AccountInformation configuration","preventionTips":["Include the AccountInformation section (accountId) in every custom Flex Query","Capture a known-good Flex report and assert the parser reads its account ids in tests","Watch IBKR Flex schema announcements for attribute renames"],"tags":["ibkr","xml","flex-query","account-mapping"],"backgroundTag":"xml-schema-validation-failed","analyzedSha":"e69894adb92547273377398c15f45c979cd9416a","analyzedAt":"2026-08-21T18:22:41.165Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}