avniproject/avni-webapp

Error on creating a Form element group with a lengthy name

Closed this issue · 5 comments

Describe the bug

An error showing up in form designer with FEG name "In the past week, did you or any household member over the age of 15 engage in any of the following activities with your child". Most probably due to the length of the FEG

To Reproduce

Steps to reproduce the behavior:

  1. Go to your test implementation
  2. Create a new FEG with this name "In the past week, did you or any household member over the age of 15 engage in any of the following activities with your child" and some questions in it
  3. Save
  4. See error
    Server error received : ERROR: value too long for type character varying(100)
2024-08-05 07:10:25.121  WARN 1569187 --- [http-nio-8021-exec-36] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 0, SQLState: 22001
2024-08-05 07:10:25.121 ERROR 1569187 --- [http-nio-8021-exec-36] o.h.engine.jdbc.spi.SqlExceptionHelper   : ERROR: value too long for type character varying(100)
2024-08-05 07:10:25.149 ERROR 1569187 --- [http-nio-8021-exec-36] org.avni.server.util.BugsnagReporter     : could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.DataException: could not execute statement

org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.DataException: could not execute statement
	at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:263)
	at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:225)
	at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:507)
	at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:61)
	at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:242)
	at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:153)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
	at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:135)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
	at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
	at com.sun.proxy.$Proxy189.findByUuidAndOrganisationId(Unknown Source)
	at org.avni.server.dao.ConceptRepository.findByUuid(ConceptRepository.java:67)
	at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627)
image

Root cause:

  • The name field of the form element group can be upto 255 chars. But whatever we receive in name we store in display field for which max characters is only 100.
  • The difference in values of display and name field is because before when creating forms via JSON files in repos we were supporting this field. But the support of different values for name and display is dropped now in 'App Designer'.

Analysis:

  • Considering presence of 255 characters for form element group name as well will fit in mobile app, since the page is scrollable, having this display field doesn't seem useful or relevant.

With 100 chars in form element group, in mobile app:
Screenshot 2024-08-05 at 2 56 12 PM

As is:

  • name field of FEG used in DEA, display field of FEG used in mobile app. So, looks like it was done to support small screens, but it doesn't seem to have helped.
  • for translations as well we seem to use name field of FEG: Code link . So for translations to work, custom keys with display value is added when needed.
  • In all cases, display value seems to be sufficient to understand the FEG name. Eg: display value: Service Details, FEG name: Mother Delivery Service Details - but here Mother and Delivery can be interpreted from program name and encounter type.

AC:

  1. Wherever the values of display and name of FEG are different, copy the value of display to FEG name field.
  2. FEG name field value should display in the mobile app as well.
  3. Remove the code/columns related to display(mobile app, web app and server).
  4. Retain FEG getters for Display, for backward compatibility support for older versions of app.
  5. So after this, we should be able to have more than 100 chars and less than 256 chars in name field of form element group
  6. Show error message 'Enter a name with less than 256 characters' when the entered name is more than 255 characters in form element and form element group.

Testing: some of the points:

  • Need backward compatibility testing with older app version and need to check if form element group name displays in mobile app.
  • Need to confirm bundle upload works fine after the change with FEG names set correctly, only for same server version used for download of bundle.

Developer Checklist(Developer fixing the bug should fill this checklist)

  • Does the fix require extensive regression testing?
    • Yes
    • No
  • Are you mentioning the required scenarios that could be affected?
    • Yes
    • No

Sample FEG / FE name string length exceeded error screen shot:
Screenshot 2024-08-29 at 2 49 37 PM

@himeshr any bundle taken before deploying this change will break when uploading. Is it possible to make this deprecated/optional instead?

@himeshr any bundle taken before deploying this change will break when uploading. Is it possible to make this deprecated/optional instead?

Replacing the "name" with "display" field contents was one of the primary ACs for this card.. which was achieved via DB migration.
Using an older server version generated bundle is not supported in-order to ensure that above mentioned change is put in effect.
Could you provide a sample bundle which breaks upload on new version.? Since, based on the code, i assumed that the name field of the old bundle would end up being returned by getDisplay() as well and we might lose the "display" field value, but not break the upload.

sample_failure_scenario.zip

Bundle upload failing for above bundle, marking it as qaFailed due to this error scenario.

FIxed old version bundle upload to work for:

  • FormElementGroup with display column and
  • GroupPrivilege without privilegeType column

The sample error bundle listed in above comment fails during upload in staging environment due to mismatch in privilegeType UUIDs across staging and prerelease/prod envs, but should work for same env old and new version of bundles.

-- Error privilege types in staging env
select *
from privilege where uuid in
                     ('cac5adae-8d99-4cef-a00b-af7d66e31a09',
'305d8287-731b-4094-8139-71bc171b242e');