Repository navigation
Closed
Labels
Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2DesignInternalRequires API changes or must be handled by Expensify staff
Description
Issue Reported by : Applause Internal Team
Action performed
- Create a workspace and expense report on the workspace
- Set the default report title to "Report field value {field:Test text}"
- Create a text report field on the policy named "Test text" with the initial value set to "initial"
- Update the initial value to "{field:Test text}"
- Open the initial value page again
- Delete the report field
- Open the policy expense chat
Expected result
- Setting the initial value of a report field, or the value of a report field, to a text value which is a formula referencing the field itself, and therefore creating a circular reference, should result in an error and the new value should not be saved
- Note: On Classic, setting the initial value of a report field to a valid formula makes the report field a "formula" type, and its value can not be manually changed on the report.
- If a report field initial value is a formula that references itself, and it is already saved in the database, because it is currently allowed on Expensify Classic, then the type of the returned report field should be changed to "text" so that it is not computed
The initial value page is not blank, and when opening the policy expense chat the app does not crash
Actual result
The initial value page is blank, and the app crashes when opening the policy expense chat
490105214-64e7dfec-1f75-472e-92ae-1bbab24580e6.mp4
OldDot behavior
2025-10-01_08-10-53.mp4
Backend code for identifying circular references
First circular references are checked for the whole formula, but on the frontend you could check passing only one "part" such as {field:someField}, and no parent fields.
string Formula::compute(SQLite& db, const JSON::Value& reportJSON, const UserDefinedFieldFormula* formula,
map<int64_t, UserCache>* userCacheMap, map<string, PolicyCache>* policyCacheMap, map<int64_t, ReportCache>* reportCacheMap, const JSON::Value& transactionJSON, const bool preventDeprecatedFormulas)
{
SDEBUG("[Formula::compute] defaultValue: " << formula->getDefaultValue().value());
const auto parts = parse(formula->getFormula());
const int64_t reportID = reportJSON.getIntMemberWithDefault("reportID", 0);
if (hasCircularReferences(db, reportID, parts, {})) {
SINFO("Formula has circular references, omitting");
return "";
}
bool Formula::hasCircularReferences(SQLite& db, int64_t reportID, const vector<unique_ptr<FormulaPart>>& parts, const vector<string>& parentFields)
{
// Prevent excessive recursion depth that could cause stack overflow
if (parentFields.size() > MAX_CIRCULAR_REFERENCE_DEPTH) {
SHMMM("Circular reference depth exceeds maximum allowed", {{"depth", to_string(parentFields.size())}, {"maxDepth", to_string(MAX_CIRCULAR_REFERENCE_DEPTH)}});
// Assume circular reference to prevent further recursion
return true;
}
for (const auto& part : parts) {
if (part->getType() != FormulaPart::TYPE_FIELD) {
continue;
}
auto* fieldPart = static_cast<FieldPart*>(part.get());
const optional<unique_ptr<UserDefinedField>>& field = fieldPart->getField(db, reportID);
if (!field.has_value()) {
continue;
}
auto* formulaField = dynamic_cast<UserDefinedFieldFormula*>(field.value().get());
if (!formulaField) {
continue;
}
const string fieldID = formulaField->getID();
if (find(parentFields.begin(), parentFields.end(), fieldID) != parentFields.end()) {
return true;
}
vector<string> newParentFields = parentFields;
newParentFields.push_back(fieldID);
if (formulaField->hasCircularReferences(db, reportID, newParentFields)) {
return true;
}
}
return false;
}
optional<unique_ptr<UserDefinedField>> FieldPart::getField(SQLite& db, int64_t reportID)
{
if (fieldPath.size() == 0) {
return nullopt;
}
string name = fieldPath[0];
auto fieldID = UserDefinedField::createFromDatabaseData<UserDefinedField>(JSON::Value({{"name", STrim(name)}, {"type", UserDefinedField::UDF_TYPE_TEXT}}))->getID();
auto udfs = Report::getUserDefinedFields(db, reportID);
for (auto& udf : udfs) {
if (udf->getID() == fieldID) {
return make_optional(move(udf));
}
}
return nullopt;
}Issue Owner
Current Issue Owner: @sonialiapMetadata
Metadata
Labels
Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2DesignInternalRequires API changes or must be handled by Expensify staff
Type
Projects
- StatusShow more project fieldsDone
Activity
melvin-bot commentedon Sep 17, 2025
Triggered auto assignment to Contributor-plus team member for initial proposal review - @DylanDylann (
External)mukhrr commentedon Sep 18, 2025
🚨 Edited by proposal-police: This proposal was edited at 2025-09-18 01:57:45 UTC.
Proposal
Please re-state the problem that we are trying to solve in this issue.
After setting report field initial value to "{field:Test text}" app crashes
What is the root cause of that problem?
It's crashish as BE is sending type as "formula" when inital value is set to "{field:Test text}" even if type is "text"
Thus, this function is causing crash:
App/src/libs/WorkspaceReportFieldUtils.ts
Lines 14 to 22 in 925b811
What changes do you think we should make in order to solve the problem?
We should give fallback text type to
getReportFieldTypeTranslationKeyandgetReportFieldAlternativeTextTranslationKey:What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?
N/A
What alternative solutions did you explore? (Optional)
But I think still root cause is from backend.
NJ-2020 commentedon Sep 18, 2025
🚨 Edited by proposal-police: This proposal was edited at 2025-09-18 10:30:22 UTC.
Proposal
Please re-state the problem that we are trying to solve in this issue.
Report field formulas: Report name is not updated to “Report field value {field:Test text}” and app crash observed
What is the root cause of that problem?
When we update the initial value field into

{field:Test text}, the BE update the field type based on the provided initial value, int this case, the BE update fromtextinto >>formulaBut since we don't have
formulakeys here, and when we try to retrieve the based on the report field type, it will return undefined here since it doesn't exist which cause thetranslatelocalize to throw an errorApp/src/pages/workspace/reports/WorkspaceReportsPage.tsx
Line 113 in 925b811
App/src/libs/WorkspaceReportFieldUtils.ts
Lines 14 to 22 in 925b811
App/src/libs/Localize/index.ts
Line 138 in 925b811
So instead of passing correct value like this:
we pass undefined which cause an error/crash
What changes do you think we should make in order to solve the problem?
Based right here, we need to add new validation check here whether if the report field initial value is containing formula pattern or not
Initial value check validation
Updating report field initial value
Updating report field value inside expense report
Test branch
Result
Screen.Recording.2025-09-29.at.09.53.14.mp4
What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?
N/A
What alternative solutions did you explore? (Optional)
N/A
NJ-2020 commentedon Sep 18, 2025
Note: I'm unsure if we should update the expense report name optimistically when updating the report field
It seems we're specifically addressing the
{field: Test text}report name update bug error/crash rather than also updating the expense name optimistically. Also, I can't preview the attached video. ThanksDylanDylann commentedon Sep 18, 2025
Does anyone know how to enable this configuration?
NJ-2020 commentedon Sep 18, 2025
@DylanDylann Here is the configuration docs
Source: #68803
DylanDylann commentedon Sep 18, 2025
@NJ-2020 Thanks for your reference
DylanDylann commentedon Sep 18, 2025
@neil-marcellini could you upload the video on the OP again? It will help us determine the bug correctly
NJ-2020 commentedon Sep 18, 2025
Proposal updated
neil-marcellini commentedon Sep 18, 2025
Oh right, sorry about that. I transferred this from our internal repository and forgot that the video link wouldn't work. It is re-uploaded now.
96 remaining items
melvin-bot commentedon Dec 2, 2025
Triggered auto assignment to @sonialiap (
Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.neil-marcellini commentedon Dec 2, 2025
Hi @sonialiap would you please handle payment?
sonialiap commentedon Dec 3, 2025
@neil-marcellini looks like the PR was submitted by NJ-2020 so the payees are NJ-2020 and DylanDylann, is that correct?
sonialiap commentedon Dec 4, 2025
Payment summary:
@DylanDylann $250 please request in NewDot
@NJ-2020 $250 offer sent in upwork - paid
NJ-2020 commentedon Dec 4, 2025
@sonialiap Thanks, accepted!
DylanDylann commentedon Dec 5, 2025
BugZero Checklist:
[Contributor] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.
Link to comment: New improvement
[Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner.
Link to discussion:
[Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.
[BugZero Assignee] Create a GH issue for creating/updating the regression test once above steps have been agreed upon.
Link to issue: https://github.com/Expensify/Expensify/issues/575550
Regression Test Proposal
Test:
Case 1: Self Reference
Case 2: 2 circular/references
Case 3: More than 2 circular/references
Case 4: No references
Case 5: Report field value / report expense
Do we agree 👍 or 👎
JmillsExpensify commentedon Jan 5, 2026
$250 approved for @DylanDylann