Skip to content

[Due for payment 2025-05-22] [$250] Profile- Setting address, select a suggested address, street name displays duplicate #60795

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
5 of 8 tasks
jponikarchuk opened this issue Apr 24, 2025 · 17 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Weekly KSv2

Comments

@jponikarchuk
Copy link

jponikarchuk commented Apr 24, 2025

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Version Number: v9.1.32-0
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught on HybridApp, is this reproducible on New Expensify Standalone?: No, reproducible on hybrid only
If this was caught during regression testing, add the test name, ID and link from TestRail: Explore
Email or phone of affected tester (no customers): N/A
Issue reported by: Applause Internal Team
Device used: Win 11/Chrome
App Component: User Settings

Action Performed:

  1. Open https://staging.new.expensify.com/
  2. Go to Profile setting
  3. Click on Address
  4. On Address line 1, type street name e.g "Ngo Quyen", "Hung Vuong" ...
  5. Select any suggested address which not included the word "Ho Chi Minh" e.g "Ngo Quyen, Quang Trung, Ha Dong, Ha Noi, Vietnam"
  6. Fill Zip/Postcode if needed and Save
  7. Click on Address
  8. On Address line 1, type street name e.g "Ngo Quyen"
  9. Select suggested address which included the word "Ho Chi Minh" e.g "Ngo Quyen, District 10, Ho Chi Minh City, Viet Nam"
  10. Fill Zip/Postcode if needed and Save

Expected Result:

Street name should display correctly

Actual Result:

Street name is duplicated in Address if the suggested isn't included the word "Ho Chi Minh"

Workaround:

Unknown

Platforms:

  • Android: Standalone
  • Android: HybridApp
  • Android: mWeb Chrome
  • iOS: Standalone
  • iOS: HybridApp
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

1.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021915446391858547053
  • Upwork Job ID: 1915446391858547053
  • Last Price Increase: 2025-04-24
Issue OwnerCurrent Issue Owner: @lschurr
@jponikarchuk jponikarchuk added Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 labels Apr 24, 2025
Copy link

melvin-bot bot commented Apr 24, 2025

Triggered auto assignment to @lschurr (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.

@CyberAndrii
Copy link
Contributor

Proposal

Please re-state the problem that we are trying to solve in this issue.

Profile - Setting address, select a suggested address, street name displays duplicate

What is the root cause of that problem?

We build the address here from streetNumber and streetName

street: `${streetNumber || streetNumberAutocompleteFallback} ${streetName || streetAutocompleteFallback}`.trim(),

The issue is that streetNumber is incorrectly set to the street name. The address parts are computed by this function:

function getPlaceAutocompleteTerms(addressTerms: AddressTerm[]): GetPlaceAutocompleteTermsResult {
const fieldsToExtract: GetPlaceAutocompleteTermsResultKey[] = ['country', 'state', 'city', 'street', 'streetNumber'];
const result: GetPlaceAutocompleteTermsResult = {};
fieldsToExtract.forEach((fieldToExtract, index) => {
const fieldTermIndex = addressTerms.length - (index + 1);
result[fieldToExtract] = fieldTermIndex >= 0 ? addressTerms.at(fieldTermIndex)?.value : '';
});
return result;
}

For example, if we search for address New York Avenue Northwest, addressTerms will have 4 elements: street, city, state, country

Image

That's the parts that the getPlaceAutocompleteTerms function is expecting, so it works correctly

/**
* Finds an address term by type, and returns the value associated to key. Note that each term in the address must
* conform to the following ORDER: <street, city, state, country>
*/
function getPlaceAutocompleteTerms(addressTerms: AddressTerm[]): GetPlaceAutocompleteTermsResult {

But for an address like Hùng Vương we get 5 elements, which causes the current logic to compute the parts incorrectly.

Image

What changes do you think we should make in order to solve the problem?

We can rewrite getPlaceAutocompleteTerms to correctly handle different values of addressTerms

function getPlaceAutocompleteTerms(addressTerms: AddressTerm[]): GetPlaceAutocompleteTermsResult  {
    const n = addressTerms.length;

    // country / state / city = always the last 3 terms
    const country = addressTerms[n - 1]?.value ?? '';
    const state   = addressTerms[n - 2]?.value ?? '';
    const city    = addressTerms[n - 3]?.value ?? '';

    // the very first term holds "number + street name"
    const firstTerm = addressTerms[0]?.value ?? '';
    const [maybeNumber, ...nameParts] = firstTerm.split(' ');

    let street       = firstTerm;
    let streetNumber = '';

    // if the first “word” is numeric, pull it out
    if (!isNaN(Number(maybeNumber))) {
        streetNumber = maybeNumber;
        street       = nameParts.join(' ');
    }

    return { country, state, city, street, streetNumber };
}

What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

Write unit test for getPlaceAutocompleteTerms that will pass different addressTerms, e.g. that have length 4, 5, include or not include a street number.

@bernhardoj
Copy link
Contributor

Proposal

Please re-state the problem that we are trying to solve in this issue.

Double street name when selecting address auto complete.

What is the root cause of that problem?

This happens after #55996. The PR is trying to fix an issue where, after selecting 1132 Murphy Ridge Rd, the street name and number is empty.

const {
street_number: streetNumber,
route: streetName,

So, they proceed to use fallbacks for the street name and number from the autocompleteData?.terms. autocompleteData?.terms is the text from the autocomplete suggestion.

street: streetAutocompleteFallback = '',
streetNumber: streetNumberAutocompleteFallback = '',
} = getPlaceAutocompleteTerms(autocompleteData?.terms ?? []);

The problem with getPlaceAutocompleteTerms is that, it requires the address format to be, <street, city, state, country>.

* Finds an address term by type, and returns the value associated to key. Note that each term in the address must
* conform to the following ORDER: <street, city, state, country>
*/
function getPlaceAutocompleteTerms(addressTerms: AddressTerm[]): GetPlaceAutocompleteTermsResult {
const fieldsToExtract: GetPlaceAutocompleteTermsResultKey[] = ['country', 'state', 'city', 'street', 'streetNumber'];
const result: GetPlaceAutocompleteTermsResult = {};
fieldsToExtract.forEach((fieldToExtract, index) => {
const fieldTermIndex = addressTerms.length - (index + 1);
result[fieldToExtract] = fieldTermIndex >= 0 ? addressTerms.at(fieldTermIndex)?.value : '';
});
return result;
}

It populates the value starting from the last index of the array. In our case, the streetNumber is populated with the street number.

Image

So, street name and number is the same.

What changes do you think we should make in order to solve the problem?

I tried searching and selecting 1132 Murphy Ridge Rd and it returns the correct result without the needs of the fallback, so it might be an API issue before. getPlaceAutocompleteTerms is not reliable, so I suggest to remove the street name and number fallback.

What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

N/A

@mkzie2
Copy link
Contributor

mkzie2 commented Apr 24, 2025

Proposal

Please re-state the problem that we are trying to solve in this issue.

Street name is duplicated in Address

What is the root cause of that problem?

In getPlaceAutocompleteTerms, we assume the order of the address terms are like this:

const fieldsToExtract: GetPlaceAutocompleteTermsResultKey[] = ['country', 'state', 'city', 'street', 'streetNumber'];

where the first term is always streetNumber. But it's not, sometimes it's just the street, for example:

Image

That makes both streetNumberAutocompleteFallback here and streetName here to be the street name. So when we're concatenating the street number and street name, we have duplicated street names:

street: `${streetNumber || streetNumberAutocompleteFallback} ${streetName || streetAutocompleteFallback}`.trim(),

What changes do you think we should make in order to solve the problem?

Remove the streetNumberAutocompleteFallback.

What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

NA

What alternative solutions did you explore? (Optional)

NA

@lschurr lschurr added the External Added to denote the issue can be worked on by a contributor label Apr 24, 2025
@melvin-bot melvin-bot bot changed the title Profile- Setting address, select a suggested address, street name displays duplicate [$250] Profile- Setting address, select a suggested address, street name displays duplicate Apr 24, 2025
Copy link

melvin-bot bot commented Apr 24, 2025

Job added to Upwork: https://www.upwork.com/jobs/~021915446391858547053

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Apr 24, 2025
Copy link

melvin-bot bot commented Apr 24, 2025

Triggered auto assignment to Contributor-plus team member for initial proposal review - @mananjadhav (External)

@ishakakkad
Copy link
Contributor

Proposal

Please re-state the problem that we are trying to solve in this issue.

Profile- Setting address, select a suggested address, street name displays duplicate

What is the root cause of that problem?

This issue is occurred after this #55996 PR. Here we have added street and streetNumber fallback to fix that issue where street and streetNumber may be empty.

street: `${streetNumber || streetNumberAutocompleteFallback} ${streetName || streetAutocompleteFallback}`.trim(),

We use getPlaceAutocompleteTerms() and passed autocompleteData?.terms to calculate fallback data. In getPlaceAutocompleteTerms() we need data in specific format but sometime that data is not return in the specific format from the google API.

Image

function getPlaceAutocompleteTerms(addressTerms: AddressTerm[]): GetPlaceAutocompleteTermsResult {
const fieldsToExtract: GetPlaceAutocompleteTermsResultKey[] = ['country', 'state', 'city', 'street', 'streetNumber'];

Because of data is not return in specific format, both streetNumberAutocompleteFallback and streetName are same due to that it display duplicate name.

What changes do you think we should make in order to solve the problem?

  1. We need to remove the streetAutocompleteFallback and streetNumberAutocompleteFallback from below place as it is not reliable data source.

street: `${streetNumber || streetNumberAutocompleteFallback} ${streetName || streetAutocompleteFallback}`.trim(),

  1. But if we will remove streetAutocompleteFallback and streetNumberAutocompleteFallback, this may reproduced the issue solve in fix: Workflows - Street doesn't get automatically filled out for a specific address. #55996. So to avoid that issue again we need to add following code here
if (!values.street && autocompleteData?.structured_formatting?.main_text) {
    values.street = autocompleteData?.structured_formatting?.main_text;
}

Here we are adding structured_formatting?.main_text as a fallback which we displayed in suggestion, so that text will always available and it is reliable.

Image Image

What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

NA

What alternative solutions did you explore? (Optional)

Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

Copy link

melvin-bot bot commented Apr 28, 2025

@mananjadhav Whoops! This issue is 2 days overdue. Let's get this updated quick!

@melvin-bot melvin-bot bot added the Overdue label Apr 28, 2025
@mananjadhav
Copy link
Collaborator

Will review the proposals today.

@melvin-bot melvin-bot bot removed the Overdue label Apr 28, 2025
@mananjadhav
Copy link
Collaborator

Well I checked and I don't think we should be updating the auto complete util as it's a bit dependent on the Google places API.

This issue is occurred after this #55996 PR. Here we have added street and streetNumber fallback to fix that issue where street and streetNumber may be empty.

I had helped with the review of the PR and even after reverting it previous one still works fine. I am inclined to use @bernhardoj's proposal. I was also trying to decide if we can use main_text, but based on what I search we don't seem to have a guarantee that main_text will always exist. Hence I feel we should go ahead with @bernhardoj's proposal.

🎀 👀 🎀 C+ reviewed.

Copy link

melvin-bot bot commented Apr 29, 2025

Triggered auto assignment to @mollfpr, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

@mollfpr
Copy link
Contributor

mollfpr commented Apr 30, 2025

Thank you all for the proposals! I'm incline to go with @bernhardoj proposal. Assigning!

@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Apr 30, 2025
@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Daily KSv2 labels May 2, 2025
@bernhardoj
Copy link
Contributor

PR is ready

cc: @mananjadhav

@melvin-bot melvin-bot bot removed the Weekly KSv2 label May 15, 2025
@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production labels May 15, 2025
@melvin-bot melvin-bot bot changed the title [$250] Profile- Setting address, select a suggested address, street name displays duplicate [Due for payment 2025-05-22] [$250] Profile- Setting address, select a suggested address, street name displays duplicate May 15, 2025
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label May 15, 2025
Copy link

melvin-bot bot commented May 15, 2025

Reviewing label has been removed, please complete the "BugZero Checklist".

Copy link

melvin-bot bot commented May 15, 2025

The solution for this issue has been 🚀 deployed to production 🚀 in version 9.1.45-21 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

If no regressions arise, payment will be issued on 2025-05-22. 🎊

For reference, here are some details about the assignees on this issue:

  • @mananjadhav requires payment through NewDot Manual Requests
  • @bernhardoj requires payment through NewDot Manual Requests

Copy link

melvin-bot bot commented May 15, 2025

@mananjadhav @lschurr @mananjadhav The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]

@lschurr
Copy link
Contributor

lschurr commented May 20, 2025

@mananjadhav - Can you work on the checklist for this one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Weekly KSv2
Projects
None yet
Development

No branches or pull requests

8 participants