Skip to content
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

Play mapping returns empty string instead of key for RepeatedMappings type #11948

Open
KeivanAbdi opened this issue Sep 7, 2023 · 0 comments · May be fixed by #11949
Open

Play mapping returns empty string instead of key for RepeatedMappings type #11948

KeivanAbdi opened this issue Sep 7, 2023 · 0 comments · May be fixed by #11949
Milestone

Comments

@KeivanAbdi
Copy link

Play Version

2.9.0-M7 (also tested on 2.8.20 and it exists there too)

API

Scala 2.13.11

Operating System

macOS 13.5.1

JDK

openjdk 17.0.8.1 2023-08-24

There is a bug in the Play mapping. Consider this as a sample mapping:

tuple(
    "a1" -> single("a2" -> nonEmptyText),
    "a3" -> list(text),
    "a4" -> number
)

We should be able to read the keys from this mapping. But instead of a3 we get an empty string.

This is a sample method for traversing the mappings and getting their keys:

def mappingFieldAddresses(mapping: Mapping[_]): Seq[String] = {

    var vector: Vector[String] = Vector.empty

    def processMapping(mapping: Mapping[_], depth: Int = 0): Unit = {
      if (mapping.mappings.size == 1) {
        vector = vector.appended(mapping.key)
      }
      if (depth == 0 || mapping.mappings.size == 1) {
        mapping.mappings.tail.foreach(processMapping(_, depth + 1))
      }
    }

    processMapping(mapping)

    vector
  }

To reproduce the bug, follow these steps:

  • Call mappingFieldAddresses with the sample mapping as an argument
  • Observe the returned sequence of strings

The expected behavior is:

  • The returned sequence should contain the keys of the mapping, such as Vector("a1.a2", "a3", "a4")

The actual behavior is:

  • The sequence contains an empty string instead of a3, such as Vector("a1.a2", "", "a4")

I have a solution that fixes this bug and passes all the tests. But I'm not sure if it is making any unpredicted new issues. I will create a pull request soon and reference this issue. Please let me know if you have any feedback or suggestions on my solution. I appreciate your help and cooperation.

@KeivanAbdi KeivanAbdi linked a pull request Sep 7, 2023 that will close this issue
7 tasks
@mkurz mkurz added this to the 2.9.1 / 3.0.1 milestone Nov 6, 2023
@mkurz mkurz modified the milestones: 2.9.1 / 3.0.1, 2.9.2 / 3.0.2 Dec 7, 2023
@mkurz mkurz modified the milestones: 2.9.2 / 3.0.2, 2.9.3 / 3.0.3 Feb 27, 2024
@mkurz mkurz modified the milestones: 3.0.3, 2.9.4 / 3.0.4 May 6, 2024
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 a pull request may close this issue.

2 participants