Expensify / App

Welcome to New Expensify: a complete re-imagination of financial collaboration, centered around chat. Help us build the next generation of Expensify by sharing feedback and contributing to the code.
https://new.expensify.com
MIT License
3.46k stars 2.82k forks source link

[$125] Tag - Error occurs when trying to add a tag named "some" #50023

Open IuliiaHerets opened 1 week ago

IuliiaHerets commented 1 week ago

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: 9.0.42-0 Reproducible in staging?: Y Reproducible in production?: Y Email or phone of affected tester (no customers): biruknew45+1289@gmail.com Issue reported by: Applause Internal Team

Action Performed:

  1. Go to https://staging.new.expensify.com/
  2. Create a workspace.
  3. Navigate to Workspace settings > more features > enable tags.
  4. Go to tags.
  5. Click on add tag.
  6. Name the tag "some" and try to save it. (ensure to write it in lowercase.)

Expected Result:

The tag named "some" should be successfully created and saved without any issues.

Actual Result:

The system returns an error stating 'A tag with this name already exists' even though no tag named 'some' is present, which might indicate a system error.

Workaround:

Unknown

Platforms:

Screenshots/Videos

https://github.com/user-attachments/assets/86eac403-a0cc-4077-938f-f5db1a43d1e7

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021841480841839544675
  • Upwork Job ID: 1841480841839544675
  • Last Price Increase: 2024-10-02
Issue OwnerCurrent Issue Owner: @allroundexperts
melvin-bot[bot] commented 1 week ago

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

IuliiaHerets commented 1 week ago

We think that this bug might be related to #wave-collect - Release 1

IuliiaHerets commented 1 week ago

@twisterdotcom FYI I haven't added the External label as I wasn't 100% sure about this issue. Please take a look and add the label if you agree it's a bug and can be handled by external contributors

Nodebrute commented 1 week ago

Edited by proposal-police: This proposal was edited at 2024-10-01 20:48:11 UTC.

Proposal

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

Error occurs when trying to add a tag named "some"

What is the root cause of that problem?

We are getting are tags list from here and when it's empty we are returning an array but tags list is supposed to be an {}.When we have values in tags list it becomes an object that's why we don't see this error while editing tag https://github.com/Expensify/App/blob/cba1457371a1466eecdb0f917c880131c063ad5b/src/libs/PolicyUtils.ts#L292-L295 And here when it's an empty array we are using an incorrect method to check https://github.com/Expensify/App/blob/def32f4dfca7eb60e07f423528d0b49a09530c37/src/pages/workspace/tags/WorkspaceCreateTagPage.tsx#L50

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

We can return {} here instead of an empty [] https://github.com/Expensify/App/blob/cba1457371a1466eecdb0f917c880131c063ad5b/src/libs/PolicyUtils.ts#L292-L295 We should also check for other places where we have this issue and fix it. We should also fix type errors that comes from this change.

What alternative solutions did you explore? (Optional)

daledah commented 1 week ago

Proposal

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

The system returns an error stating 'A tag with this name already exists' even though no tag named 'some' is present, which might indicate a system error.

What is the root cause of that problem?

In

https://github.com/Expensify/App/blob/cba1457371a1466eecdb0f917c880131c063ad5b/src/pages/workspace/tags/WorkspaceCreateTagPage.tsx#L50-L51

We check if tags has property tagName to determine if the created tag already exist.

However, when we create a new workspace, the tags object is an array:

Screenshot 2024-10-02 at 03 43 24

it will only be updated to an object when a tag is created.

And some is a property of a Javascript's array object, which leads to tags?.[tagName] exists, make the error appears. The same bug can happen with other array properties aswell, such as every, forEach, etc.

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

  1. We can fix this from the BE side so the returned Tag is always an object
  2. We can change the logic to handle array:

Update

https://github.com/Expensify/App/blob/cba1457371a1466eecdb0f917c880131c063ad5b/src/pages/workspace/tags/WorkspaceCreateTagPage.tsx#L50

to

else if (!Array.isArray(tags) && tags?.[tagName]) {

or

else if (Object.prototype.hasOwnProperty.call(tags, tagName)){

What alternative solutions did you explore? (Optional)

NA

twisterdotcom commented 1 week ago

What a weird bug. Easy to recreate.

image
melvin-bot[bot] commented 1 week ago

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

melvin-bot[bot] commented 1 week ago

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

melvin-bot[bot] commented 1 week ago

Upwork job price has been updated to $125

Nodebrute commented 1 week ago

I believe this may be a backend issue. The tags are supposed to be {} on the frontend, and we have set them correctly. However, when we create a workspace, the tags are being set to [] instead. I think the backend should ensure that the tags are set to {}.

Screenshot 2024-10-02 at 7 55 08 PM

https://github.com/Expensify/App/blob/3946b226d6367a719af5bc894546b95dc9b59fb4/src/libs/actions/Policy/Tag.ts#L639 https://github.com/Expensify/App/blob/3946b226d6367a719af5bc894546b95dc9b59fb4/src/libs/PolicyUtils.ts#L311

cc: @allroundexperts @twisterdotcom

sher999 commented 1 week ago

Proposal

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

Error occurs when trying to add a tag named "some"

What is the root cause of that problem?

checking on empty array is returning [Function some] https://github.com/Expensify/App/blob/1ed31aa7232050cc38ee4b2050ed56a6ccf80403/src/pages/workspace/tags/WorkspaceCreateTagPage.tsx#L50

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

Check the lenght of the tags array if it is empty js will return false and skip the "else if" condition

 } else if (tags?.[tagName] && tags.length) { 

Checked on staging

ios native

https://github.com/user-attachments/assets/b599bb26-8aa1-4154-89c2-4f61e628cdf1

What alternative solutions did you explore? (Optional)

allroundexperts commented 4 days ago

@twisterdotcom I think that a backend fix would be better. Can you please pull someone from the internal team to take a look? TY!

twisterdotcom commented 4 days ago

cc @yuwenmemon can you do this?

yuwenmemon commented 4 days ago

Lolwut this is odd

twisterdotcom commented 3 days ago

Open source finds only the best bugs.