The Wayback Machine - https://web.archive.org/web/20200915093529/https://github.com/DOMjudge/domjudge/issues/841
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

Register: Error when affiliation name is longer than 32 chars #841

Open
tom93 opened this issue Jun 26, 2020 · 3 comments
Open

Register: Error when affiliation name is longer than 32 chars #841

tom93 opened this issue Jun 26, 2020 · 3 comments

Comments

@tom93
Copy link
Contributor

@tom93 tom93 commented Jun 26, 2020

Description of the problem

During registration, if a new affiliation is added with a name longer than 32 characters, the server returns a 500 Internal Server Error page.

An exception occurred while executing 'INSERT INTO team_affiliation (externalid, shortname, name, country, comments) VALUES (?, ?, ?, ?, ?)' with params [null, "A very long team affiliation name", "A very long team affiliation name", null, null]:

SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'shortname' at row 1

Environment

DOMjudge 7.1.3, 7.2.1, master @ aac01de.

Expected behaviour

Either registration should succeed, or there should be a friendly error message.
(I think this is reasonable to expect because the limit is so small.)

Cause

The input from the user is used as both the name and the shortname of the new affiliation. The length limit of the name is 255, while the length limit of the shortname is only 32.

Ideas for fix

  • Add validation to forbid names longer than 32 characters (simple, but needlessly restricts the length of the full name).
  • Truncate the input to 32 characters for the shortname (may result in duplicate shortnames; not sure if this is a problem, e.g. for exporting/importing).
  • Generate a unique shortname (e.g. first 20 characters of user input followed by an incrementing integer).

I'd be happy to implement one of these, just not sure what the preferred approach would be.

Stack trace

Doctrine\DBAL\Exception\DriverException:
An exception occurred while executing 'INSERT INTO team_affiliation (externalid, shortname, name, country, comments) VALUES (?, ?, ?, ?, ?)' with params [null, "A very long team affiliation name", "A very long team affiliation name", null, null]:

SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'shortname' at row 1

  at /domjudge/lib/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php:106
  at Doctrine\DBAL\Driver\AbstractMySQLDriver->convertException()
     (/domjudge/lib/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:169)
  at Doctrine\DBAL\DBALException::wrapException()
     (/domjudge/lib/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:149)
  at Doctrine\DBAL\DBALException::driverExceptionDuringQuery()
     (/domjudge/lib/vendor/doctrine/dbal/lib/Doctrine/DBAL/Statement.php:162)
  at Doctrine\DBAL\Statement->execute()
     (/domjudge/lib/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php:287)
  at Doctrine\ORM\Persisters\Entity\BasicEntityPersister->executeInserts()
     (/domjudge/lib/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:1087)
  at Doctrine\ORM\UnitOfWork->executeInserts()
     (/domjudge/lib/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:400)
  at Doctrine\ORM\UnitOfWork->commit()
     (/domjudge/lib/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:368)
  at Doctrine\ORM\EntityManager->flush()
     (src/Controller/SecurityController.php:177)
  at App\Controller\SecurityController->registerAction()
     (/domjudge/lib/vendor/symfony/http-kernel/HttpKernel.php:158)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw()
     (/domjudge/lib/vendor/symfony/http-kernel/HttpKernel.php:80)
  at Symfony\Component\HttpKernel\HttpKernel->handle()
     (/domjudge/lib/vendor/symfony/http-kernel/Kernel.php:201)
  at Symfony\Component\HttpKernel\Kernel->handle()
     (public/index.php:25)
@thijskh
Copy link
Member

@thijskh thijskh commented Jun 26, 2020

For the record, it only fails when MySQL is in some kind of strict mode. In my (default Debian) installation, it does not fail but the value is silently truncated, which we all know and love from MySQL.

In the admin interface we do not currently enforce any shortname uniqueness.

I doubt there's much to gain from making the self-registered shortnames forcefully unique. Because in self registration we currently accept long names "Utrecht University" and "Universiteit Utrecht" and "Utrecht University " as all new affiliations. Only exact stringwise matches are not accepted. So there's no real expectation of uniqueness for self-declared affiliations, I think. So also not for shortnames?

@thijskh
Copy link
Member

@thijskh thijskh commented Jun 27, 2020

A fourth option is to ask the user to also provide a meaningful shortname during registration.

@eldering
Copy link
Member

@eldering eldering commented Jun 27, 2020

To me asking the user for a shortname and otherwise generate a unique one from the affiliation name sounds like a good candidate solution. Although just picking either of those is also fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.